Ticket #36477: 36477_2.diff
File 36477_2.diff, 2.0 KB (added by , 4 years ago) |
---|
-
src/wp-includes/class-wp-image-editor-imagick.php
23 23 */ 24 24 protected $image; 25 25 26 /** 27 * Stores the information whether the image is indexed-color encoded 28 * 29 * @since 4.7 30 * @access protected 31 * @var bool 32 */ 33 protected $indexed_color_encoded = false; 34 26 35 public function __destruct() { 27 36 if ( $this->image instanceof Imagick ) { 28 37 // we don't need the original in memory anymore … … 303 312 ); 304 313 305 314 /** 315 * Check image type whether it's using palette (indexed-color encoded). 316 * Use this property when saving the resized image to preserved its original image type. 317 * This will reduce occurrences of having a resized image filesize very much larger than the original. 318 * @since 4.7 319 */ 320 if ( ( is_callable( array( $this->image, 'getImageType' ) ) ) && ( defined( 'imagick::IMGTYPE_PALETTE' ) ) ) { 321 $image_type = $this->image->getImageType(); 322 if ( imagick::IMGTYPE_PALETTE === $image_type ) { 323 $this->indexed_color_encoded = true; 324 } 325 } 326 327 /** 306 328 * Set the filter value if '$filter_name' name is in our whitelist and the related 307 329 * Imagick constant is defined or fall back to our default filter. 308 330 */ … … 620 642 // Store initial Format 621 643 $orig_format = $this->image->getImageFormat(); 622 644 645 // Restore image type when saving the image to preserved original colors and optimized its file size. 646 if ( ( is_callable( array( $this->image, 'getImageType' ) ) ) && ( true === $this->indexed_color_encoded ) && ( defined( 'imagick::IMGTYPE_PALETTE' ) ) ) { 647 $this->image->setImageType( imagick::IMGTYPE_PALETTE ); 648 } 649 623 650 $this->image->setImageFormat( strtoupper( $this->get_extension( $mime_type ) ) ); 624 651 $this->make_image( $filename, array( $image, 'writeImage' ), array( $filename ) ); 625 652