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 { |
21 | 21 | */ |
22 | 22 | protected $image; |
23 | 23 | |
| 24 | private $can_use_filehandles = false; |
| 25 | |
24 | 26 | public function __destruct() { |
25 | 27 | if ( $this->image instanceof Imagick ) { |
26 | 28 | // we don't need the original in memory anymore |
… |
… |
class WP_Image_Editor_Imagick extends WP_Image_Editor { |
82 | 84 | return false; |
83 | 85 | } |
84 | 86 | |
| 87 | if ( in_array( 'writeimagefile', $class_methods ) && in_array( 'readimagefile', $class_methods ) ) { |
| 88 | $this->can_use_filehandles = true; |
| 89 | } |
| 90 | |
85 | 91 | // HHVM Imagick does not support loading from URL, so fail to allow fallback to GD. |
86 | 92 | if ( defined( 'HHVM_VERSION' ) && isset( $args['path'] ) && preg_match( '|^https?://|', $args['path'] ) ) { |
87 | 93 | return false; |
… |
… |
class WP_Image_Editor_Imagick extends WP_Image_Editor { |
150 | 156 | |
151 | 157 | // Reading image after Imagick instantiation because `setResolution` |
152 | 158 | // only applies correctly before the image is read. |
153 | | $this->image->readImage( $filename ); |
| 159 | if ( $this->can_use_filehandles ) { |
| 160 | $this->image->readImageFile( fopen( $filename, 'rb' ) ); |
| 161 | } else { |
| 162 | $this->image->readImage( $filename ); |
| 163 | } |
154 | 164 | |
155 | 165 | if ( ! $this->image->valid() ) |
156 | 166 | return new WP_Error( 'invalid_image', __('File is not an image.'), $this->file); |
… |
… |
class WP_Image_Editor_Imagick extends WP_Image_Editor { |
623 | 633 | $orig_format = $this->image->getImageFormat(); |
624 | 634 | |
625 | 635 | $this->image->setImageFormat( strtoupper( $this->get_extension( $mime_type ) ) ); |
626 | | $this->make_image( $filename, array( $image, 'writeImage' ), array( $filename ) ); |
| 636 | if ( $this->can_use_filehandles ) { |
| 637 | $fp = fopen( $filename, 'w+b' ); |
| 638 | $this->make_image( $filename, array( $image, 'writeImageFile' ), array( $fp ) ); |
| 639 | } else { |
| 640 | $this->make_image( $filename, array( $image, 'writeImage' ), array( $filename ) ); |
| 641 | } |
627 | 642 | |
628 | 643 | // Reset original Format |
629 | 644 | $this->image->setImageFormat( $orig_format ); |