WP_Image_Editor::maybe_exif_rotate(): bool|WP_Error
- Since
- 5.3.0
- Source
wp-includes/class-wp-image-editor.php:486
Compatibility
- WordPress
- since 5.3.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.
Return value
bool|WP_Error- True if the image was rotated. False if not rotated (no EXIF data or the image doesn't need to be rotated).
WP_Error if error while rotating.
Performance profile
How much work a call to WP_Image_Editor::maybe_exif_rotate() 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
- 15–58
- Plugin surface
- 1 hook
- Called by
- 1
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 104.
Third-party callbacks on 'wp_image_maybe_exif_rotate' run inside this call, and their cost is not bounded by anything here.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly
What one call costs · 10 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Image_Editor::maybe_exif_rotate() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 15–35 | is_callable(), apply_filters() |
$orientation !== 1 | 22–39 | is_callable(), apply_filters(), ->rotate() |
$orientation !== 1 | 23–32 | is_callable(), apply_filters(), ->flip() |
$orientation !== 1 && is_wp_error() | 26–41 | is_callable(), apply_filters(), ->rotate(), is_wp_error() |
is_callable() | 28–47 | is_callable(), exif_read_data(), apply_filters() |
$orientation !== 1 && !is_wp_error() | 31–46 | is_callable(), apply_filters(), ->rotate(), is_wp_error(), ->flip() |
is_callable() && $orientation !== 1 | 35–51 | is_callable(), exif_read_data(), apply_filters(), ->rotate() |
is_callable() && $orientation !== 1 | 36–44 | is_callable(), exif_read_data(), apply_filters(), ->flip() |
is_callable() && $orientation !== 1 && is_wp_error() | 39–53 | is_callable(), exif_read_data(), apply_filters(), ->rotate(), is_wp_error() |
is_callable() && $orientation !== 1 && !is_wp_error() | 44–58 | is_callable(), exif_read_data(), apply_filters(), ->rotate(), is_wp_error(), ->flip() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 104 | 15–58 | 15 | |
| 8.5 | 104 | 15–58 | 15 | |
| 8.4 | 104 | 15–58 | 15 | |
| 8.3 | 104 | 15–58 | 15 | |
| 8.2 | 104 | 15–58 | 15 | |
| 8.1 | 104 | 15–58 | 15 | 1 more instruction than PHP 7.4 |
| 7.4 | 103 | 15–58 | 15 |
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.
Hooks and filters fired · 1
One hook fires while WP_Image_Editor::maybe_exif_rotate() runs, in this order:
- apply_filters( wp_image_maybe_exif_rotate )filterline 505 (+19 into the body)
Filters the `$orientation` value to correct it before rotating or to prevent rotating the image.
Uses · 4
- apply_filters()Calls the callback functions that have been added to a filter hook.
- is_wp_error()Checks whether the given variable is a WordPress Error.
- WP_Image_Editor::flip()Flips current image.
- WP_Image_Editor::rotate()Rotates current image counter-clockwise by $angle.
Used by · 1
- WP_Image_Editor_Imagick::maybe_exif_rotate()Check if a JPEG image has EXIF Orientation tag and rotate it if needed.
Source code
public function maybe_exif_rotate() { $orientation = null; if ( is_callable( 'exif_read_data' ) && 'image/jpeg' === $this->mime_type ) { $exif_data = @exif_read_data( $this->file ); if ( ! empty( $exif_data['Orientation'] ) ) { $orientation = (int) $exif_data['Orientation']; } } /** * Filters the `$orientation` value to correct it before rotating or to prevent rotating the image. * * @since 5.3.0 * * @param int $orientation EXIF Orientation value as retrieved from the image file. * @param string $file Path to the image file. */ $orientation = apply_filters( 'wp_image_maybe_exif_rotate', $orientation, $this->file ); if ( ! $orientation || 1 === $orientation ) { return false; } switch ( $orientation ) { case 2: // Flip horizontally. $result = $this->flip( false, true ); break; case 3: /* * Rotate 180 degrees or flip horizontally and vertically. * Flipping seems faster and uses less resources. */ $result = $this->flip( true, true ); break; case 4: // Flip vertically. $result = $this->flip( true, false ); break; case 5: // Rotate 90 degrees counter-clockwise and flip vertically. $result = $this->rotate( 90 ); if ( ! is_wp_error( $result ) ) { $result = $this->flip( true, false ); } break; case 6: // Rotate 90 degrees clockwise (270 counter-clockwise). $result = $this->rotate( 270 ); break; case 7: // Rotate 90 degrees counter-clockwise and flip horizontally. $result = $this->rotate( 90 ); if ( ! is_wp_error( $result ) ) { $result = $this->flip( false, true ); } break; case 8: // Rotate 90 degrees counter-clockwise. $result = $this->rotate( 90 ); break; } return $result; }Changelog
Introduced in 5.3.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.0.4 tag, from
src/wp-includes/class-wp-image-editor.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.