Changeset 49230 for trunk/src/wp-includes/class-wp-image-editor-imagick.php
- Timestamp:
- 10/20/2020 02:35:10 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-image-editor-imagick.php
r49174 r49230 72 72 'flopimage', 73 73 'readimage', 74 'readimageblob', 74 75 ); 75 76 … … 128 129 } 129 130 130 if ( ! is_file( $this->file ) && ! preg_match( '|^https?://|',$this->file ) ) {131 if ( ! is_file( $this->file ) && ! wp_is_stream( $this->file ) ) { 131 132 return new WP_Error( 'error_loading_image', __( 'File doesn’t exist?' ), $this->file ); 132 133 } … … 149 150 } 150 151 } else { 151 $this->image->readImage( $this->file ); 152 if ( wp_is_stream( $this->file ) ) { 153 // Due to reports of issues with streams with `Imagick::readImageFile()`, uses `Imagick::readImageBlob()` instead. 154 $this->image->readImageBlob( file_get_contents( $this->file ), $this->file ); 155 } else { 156 $this->image->readImage( $this->file ); 157 } 152 158 } 153 159 … … 683 689 684 690 $this->image->setImageFormat( strtoupper( $this->get_extension( $mime_type ) ) ); 685 $this->make_image( $filename, array( $image, 'writeImage' ), array( $filename ) ); 686 691 } catch ( Exception $e ) { 692 return new WP_Error( 'image_save_error', $e->getMessage(), $filename ); 693 } 694 695 $write_image_result = $this->write_image( $this->image, $filename ); 696 if ( is_wp_error( $write_image_result ) ) { 697 return $write_image_result; 698 } 699 700 try { 687 701 // Reset original format. 688 702 $this->image->setImageFormat( $orig_format ); … … 704 718 'mime-type' => $mime_type, 705 719 ); 720 } 721 722 /** 723 * Writes an image to a file or stream. 724 * 725 * @since 5.6 726 * 727 * @param Imagick $image 728 * @param string $filename The destination filename or stream URL. 729 * 730 * @return true|WP_Error 731 */ 732 private function write_image( $image, $filename ) { 733 if ( wp_is_stream( $filename ) ) { 734 /* 735 * Due to reports of issues with streams with `Imagick::writeImageFile()` and `Imagick::writeImage()`, copies the blob instead. 736 * Checks for exact type due to: https://www.php.net/manual/en/function.file-put-contents.php 737 */ 738 if ( file_put_contents( $filename, $image->getImageBlob() ) === false ) { 739 /* translators: %s: PHP function name. */ 740 return new WP_Error( 'image_save_error', sprintf( __( '%s failed while writing image to stream.' ), '<code>file_put_contents()</code>' ), $filename ); 741 } else { 742 return true; 743 } 744 } else { 745 try { 746 return $image->writeImage( $filename ); 747 } catch ( Exception $e ) { 748 return new WP_Error( 'image_save_error', $e->getMessage(), $filename ); 749 } 750 } 706 751 } 707 752
Note: See TracChangeset
for help on using the changeset viewer.