WP_Image_Editor_Imagick::update_size( int $width = null, int $height = null ): true|WP_Error
- Since
- 3.5.0
- Source
wp-includes/class-wp-image-editor-imagick.php:452
Compatibility
- WordPress
- since 3.5.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$widthintoptional- Default:
null $heightintoptional- Default:
null
Return value
true|WP_Error
Performance profile
How much work a call to WP_Image_Editor_Imagick::update_size() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Trivial
- Scaling
- Constant
- Instructions
- 14–42
- Plugin surface
- None
- Called by
- 4
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 54.
Nothing here hands control to plugin code.
4 places in core call this, so the cost is paid more often than your own code shows.
What one call costs · 8 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Image_Editor_Imagick::update_size() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 14–18 | ::update_size() |
| always | 18–23 | ->getImageGeometry(), ::update_size() |
!wp_is_heic_image_mime_type() | 22–27 | wp_is_heic_image_mime_type(), ::update_size() |
| always | 26–31 | wp_getimagesize(), ::update_size() |
!wp_is_heic_image_mime_type() | 26–32 | ->getImageGeometry(), wp_is_heic_image_mime_type(), ::update_size() |
| always | 30–36 | ->getImageGeometry(), wp_getimagesize(), ::update_size() |
wp_is_heic_image_mime_type() | 32–37 | wp_is_heic_image_mime_type(), wp_getimagesize(), ::update_size() |
wp_is_heic_image_mime_type() | 36–42 | ->getImageGeometry(), wp_is_heic_image_mime_type(), wp_getimagesize(), ::update_size() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 54 instructions, 14–42 executed per call, 8 branches. The work does not change between versions.
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Uses · 5
- __()Retrieves the translation of $text.
- wp_is_heic_image_mime_type()Checks if a mime type is for a HEIC/HEIF image.
- wp_getimagesize()Allows PHP's getimagesize() to be debuggable when necessary.
- WP_Error::__construct()Initializes the error.
- WP_Image_Editor::update_size()Sets current image size.
Used by · 4
- WP_Image_Editor_Imagick::crop()Crops Image.
- WP_Image_Editor_Imagick::load()Loads image from $this->file into new Imagick Object.
- WP_Image_Editor_Imagick::resize()Resizes current image.
- WP_Image_Editor_Imagick::rotate()Rotates current image counter-clockwise by $angle.
Source code
protected function update_size( $width = null, $height = null ) { $size = null; if ( ! $width || ! $height ) { try { $size = $this->image->getImageGeometry(); } catch ( Exception $e ) { return new WP_Error( 'invalid_image', __( 'Could not read image size.' ), $this->file ); } } if ( ! $width ) { $width = $size['width']; } if ( ! $height ) { $height = $size['height']; } /* * If we still don't have the image size, fall back to `wp_getimagesize`. This ensures AVIF and HEIC images * are properly sized without affecting previous `getImageGeometry` behavior. */ if ( ( ! $width || ! $height ) && ( 'image/avif' === $this->mime_type || wp_is_heic_image_mime_type( $this->mime_type ) ) ) { $size = wp_getimagesize( $this->file ); $width = $size[0]; $height = $size[1]; } return parent::update_size( $width, $height ); }Changelog
Introduced in 3.5.0. 2 changes between 6.7.7 and 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
$width retyped from int to int|null.verified against source$height retyped from int to int|null.verified against sourceAbout this page
- Parsed data
- Generated from the wordpress-develop 6.7.7 tag, from
src/wp-includes/class-wp-image-editor-imagick.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.