maybe_exif_rotate example

if ( is_wp_error( $editor ) ) {
                // This image cannot be edited.                 return $image_meta;
            }

            // Resize the image.             $resized = $editor->resize( $threshold$threshold );
            $rotated = null;

            // If there is EXIF data, rotate according to EXIF Orientation.             if ( ! is_wp_error( $resized ) && is_array( $exif_meta ) ) {
                $resized = $editor->maybe_exif_rotate();
                $rotated = $resized;
            }

            if ( ! is_wp_error( $resized ) ) {
                /* * Append "-scaled" to the image file name. It will look like "my_image-scaled.jpg". * This doesn't affect the sub-sizes names as they are generated from the original image (for best quality). */
                $saved = $editor->save( $editor->generate_filename( 'scaled' ) );

                if ( ! is_wp_error( $saved ) ) {
                    

    public function maybe_exif_rotate() {
        if ( is_callable( array( $this->image, 'setImageOrientation' ) ) && defined( 'Imagick::ORIENTATION_TOPLEFT' ) ) {
            return parent::maybe_exif_rotate();
        } else {
            return new WP_Error( 'write_exif_error', __( 'The image cannot be rotated because the embedded meta data cannot be updated.' ) );
        }
    }

    /** * Saves current image to file. * * @since 3.5.0 * @since 6.0.0 The `$filesize` value was added to the returned array. * * @param string $destfilename Optional. Destination filename. Default null. * @param string $mime_type Optional. The mime-type. Default null. * @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. * } */
Home | Imprint | This part of the site doesn't use cookies.