diff -r 7b1b88e27a20 -r 48c4eec2b7e6 wp/wp-includes/class-wp-image-editor.php --- a/wp/wp-includes/class-wp-image-editor.php Thu Sep 29 08:06:27 2022 +0200 +++ b/wp/wp-includes/class-wp-image-editor.php Fri Sep 05 18:40:08 2025 +0200 @@ -11,6 +11,7 @@ * * @since 3.5.0 */ +#[AllowDynamicProperties] abstract class WP_Image_Editor { protected $file = null; protected $size = null; @@ -75,11 +76,21 @@ * Saves current image to file. * * @since 3.5.0 + * @since 6.0.0 The `$filesize` value was added to the returned array. * @abstract * * @param string $destfilename Optional. Destination filename. Default null. * @param string $mime_type Optional. The mime-type. Default null. - * @return array|WP_Error {'path'=>string, 'file'=>string, 'width'=>int, 'height'=>int, 'mime-type'=>string} + * @return array|WP_Error { + * Array on success or WP_Error if the file failed to save. + * + * @type string $path Path to the image file. + * @type string $file Name of the image file. + * @type int $width Image width. + * @type int $height Image height. + * @type string $mime-type The mime type of the image. + * @type int $filesize File size of the image. + * } */ abstract public function save( $destfilename = null, $mime_type = null ); @@ -93,9 +104,16 @@ * @since 3.5.0 * @abstract * - * @param int|null $max_w Image width. - * @param int|null $max_h Image height. - * @param bool $crop + * @param int|null $max_w Image width. + * @param int|null $max_h Image height. + * @param bool|array $crop { + * Optional. Image cropping behavior. If false, the image will be scaled (default). + * If true, image will be cropped to the specified dimensions using center positions. + * If an array, the image will be cropped using the array to specify the crop location: + * + * @type string $0 The x crop position. Accepts 'left' 'center', or 'right'. + * @type string $1 The y crop position. Accepts 'top', 'center', or 'bottom'. + * } * @return true|WP_Error */ abstract public function resize( $max_w, $max_h, $crop = false ); @@ -110,9 +128,9 @@ * An array of image size arrays. Default sizes are 'small', 'medium', 'large'. * * @type array ...$0 { - * @type int $width Image width. - * @type int $height Image height. - * @type bool $crop Optional. Whether to crop the image. Default false. + * @type int $width Image width. + * @type int $height Image height. + * @type bool|array $crop Optional. Whether to crop the image. Default false. * } * } * @return array An array of resized images metadata by size. @@ -300,6 +318,7 @@ $quality = 86; break; case 'image/jpeg': + case 'image/avif': default: $quality = $this->default_quality; } @@ -338,9 +357,11 @@ $file_mime = $this->mime_type; } - // Check to see if specified mime-type is the same as type implied by - // file extension. If so, prefer extension from file. - if ( ! $mime_type || ( $file_mime == $mime_type ) ) { + /* + * Check to see if specified mime-type is the same as type implied by + * file extension. If so, prefer extension from file. + */ + if ( ! $mime_type || ( $file_mime === $mime_type ) ) { $mime_type = $file_mime; $new_ext = $file_ext; } @@ -373,8 +394,10 @@ $new_ext = $this->get_extension( $mime_type ); } - // Double-check that the mime-type selected is supported by the editor. - // If not, choose a default instead. + /* + * Double-check that the mime-type selected is supported by the editor. + * If not, choose a default instead. + */ if ( ! $this->supports_mime_type( $mime_type ) ) { /** * Filters default mime type prior to getting the file extension. @@ -389,9 +412,11 @@ $new_ext = $this->get_extension( $mime_type ); } - // Ensure both $filename and $new_ext are not empty. - // $this->get_extension() returns false on error which would effectively remove the extension - // from $filename. That shouldn't happen, files without extensions are not supported. + /* + * Ensure both $filename and $new_ext are not empty. + * $this->get_extension() returns false on error which would effectively remove the extension + * from $filename. That shouldn't happen, files without extensions are not supported. + */ if ( $filename && $new_ext ) { $dir = pathinfo( $filename, PATHINFO_DIRNAME ); $ext = pathinfo( $filename, PATHINFO_EXTENSION ); @@ -403,8 +428,8 @@ // The image will be converted when saving. Set the quality for the new mime-type if not already set. if ( $mime_type !== $this->output_mime_type ) { $this->output_mime_type = $mime_type; - $this->set_quality(); } + $this->set_quality(); } elseif ( ! empty( $this->output_mime_type ) ) { // Reset output_mime_type and quality. $this->output_mime_type = null; @@ -501,23 +526,25 @@ switch ( $orientation ) { case 2: // Flip horizontally. - $result = $this->flip( true, false ); + $result = $this->flip( false, true ); break; case 3: - // Rotate 180 degrees or flip horizontally and vertically. - // Flipping seems faster and uses less resources. + /* + * 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( false, true ); + $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( false, true ); + $result = $this->flip( true, false ); } break; @@ -530,7 +557,7 @@ $result = $this->rotate( 90 ); if ( ! is_wp_error( $result ) ) { - $result = $this->flip( true, false ); + $result = $this->flip( false, true ); } break; @@ -628,4 +655,3 @@ return wp_get_default_extension_for_mime_type( $mime_type ); } } -