Make WordPress Core

Ticket #42663: imagick.2.diff

File imagick.2.diff, 2.1 KB (added by calin, 6 years ago)
  • wp-includes/class-wp-image-editor-imagick.php

    diff --git a/wp-includes/class-wp-image-editor-imagick.php b/wp-includes/class-wp-image-editor-imagick.php
    index 9f6a0f3b52..48a521a677 100644
    a b class WP_Image_Editor_Imagick extends WP_Image_Editor { 
    2121         */
    2222        protected $image;
    2323
     24        static protected $can_use_filehandles = false;
     25
    2426        public function __destruct() {
    2527                if ( $this->image instanceof Imagick ) {
    2628                        // we don't need the original in memory anymore
    class WP_Image_Editor_Imagick extends WP_Image_Editor { 
    8284                        return false;
    8385                }
    8486
     87                if ( in_array( 'writeimagefile', $class_methods ) && in_array( 'readimagefile', $class_methods ) ) {
     88                        self::$can_use_filehandles = true;
     89                }
     90
    8591                // HHVM Imagick does not support loading from URL, so fail to allow fallback to GD.
    8692                if ( defined( 'HHVM_VERSION' ) && isset( $args['path'] ) && preg_match( '|^https?://|', $args['path'] ) ) {
    8793                        return false;
    class WP_Image_Editor_Imagick extends WP_Image_Editor { 
    150156
    151157                        // Reading image after Imagick instantiation because `setResolution`
    152158                        // only applies correctly before the image is read.
    153                         $this->image->readImage( $filename );
     159                        if ( self::$can_use_filehandles ) {
     160                                $this->image->readImageFile( fopen( $filename, 'rb' ) );
     161                        } else {
     162                                $this->image->readImage( $filename );
     163                        }
    154164
    155165                        if ( ! $this->image->valid() )
    156166                                return new WP_Error( 'invalid_image', __('File is not an image.'), $this->file);
    class WP_Image_Editor_Imagick extends WP_Image_Editor { 
    623633                        $orig_format = $this->image->getImageFormat();
    624634
    625635                        $this->image->setImageFormat( strtoupper( $this->get_extension( $mime_type ) ) );
    626                         $this->make_image( $filename, array( $image, 'writeImage' ), array( $filename ) );
     636                        if ( self::$can_use_filehandles ) {
     637                                $fp = fopen( $filename, 'wb' );
     638                                $this->make_image( $filename, array( $image, 'writeImageFile' ), array( $fp ) );
     639                        } else {
     640                                $this->make_image( $filename, array( $image, 'writeImage' ), array( $filename ) );
     641                        }
    627642
    628643                        // Reset original Format
    629644                        $this->image->setImageFormat( $orig_format );