Ticket #33642: 33642.10.patch
File 33642.10.patch, 6.8 KB (added by , 9 years ago) |
---|
-
src/wp-includes/class-wp-image-editor-imagick.php
diff --git src/wp-includes/class-wp-image-editor-imagick.php src/wp-includes/class-wp-image-editor-imagick.php index 125ef0d..730e048 100644
class WP_Image_Editor_Imagick extends WP_Image_Editor { 62 62 'writeimage', 63 63 'getimageblob', 64 64 'getimagegeometry', 65 'getimagedepth',66 65 'getimageformat', 67 66 'setimageformat', 68 67 'setimagecompression', 69 68 'setimagecompressionquality', 70 'setimagedepth',71 69 'setimagepage', 72 'setimageproperty',73 'setinterlacescheme',74 70 'scaleimage', 75 71 'cropimage', 76 72 'rotateimage', 77 73 'flipimage', 78 74 'flopimage', 79 'unsharpmaskimage',80 75 ); 81 76 82 77 // Now, test for deep requirements within Imagick. 83 if ( ! ( defined( 'imagick::COMPRESSION_JPEG' ) && defined( 'imagick::FILTER_TRIANGLE' )) )78 if ( ! defined( 'imagick::COMPRESSION_JPEG' ) ) 84 79 return false; 85 80 86 81 if ( array_diff( $required_methods, get_class_methods( 'Imagick' ) ) ) … … class WP_Image_Editor_Imagick extends WP_Image_Editor { 304 299 if ( in_array( $filter_name, $allowed_filters ) && defined( 'Imagick::' . $filter_name ) ) { 305 300 $filter = constant( 'Imagick::' . $filter_name ); 306 301 } else { 307 $filter = Imagick::FILTER_TRIANGLE;302 $filter = defined( 'Imagick::FILTER_TRIANGLE' ) ? Imagick::FILTER_TRIANGLE : false; 308 303 } 309 304 310 305 /** … … class WP_Image_Editor_Imagick extends WP_Image_Editor { 334 329 * whenever the output size is less that 1/3 of the original image size (1/3^2 ~= .111), 335 330 * unless we would be resampling to a scale smaller than 128x128. 336 331 */ 337 $resize_ratio = ( $dst_w / $this->size['width'] ) * ( $dst_h / $this->size['height'] ); 338 $sample_factor = 5; 332 if ( is_callable( array( $this->image, 'sampleImage' ) ) ) { 333 $resize_ratio = ( $dst_w / $this->size['width'] ) * ( $dst_h / $this->size['height'] ); 334 $sample_factor = 5; 339 335 340 if ( $resize_ratio < .111 && ( $dst_w * $sample_factor > 128 && $dst_h * $sample_factor > 128 ) ) { 341 $this->image->sampleImage( $dst_w * $sample_factor, $dst_h * $sample_factor ); 336 if ( $resize_ratio < .111 && ( $dst_w * $sample_factor > 128 && $dst_h * $sample_factor > 128 ) ) { 337 $this->image->sampleImage( $dst_w * $sample_factor, $dst_h * $sample_factor ); 338 } 342 339 } 343 340 344 // Resize to the final output size. 345 $this->image->setOption( 'filter:support', '2.0' ); 346 $this->image->resizeImage( $dst_w, $dst_h, $filter, 1 ); 341 /** 342 * Use resizeImage() when it's availalbe and a valid filter value is set. 343 * Otherwise, fall back to the scaleImage() method for resizing, which 344 * results in better image quality over resizeImage() with default filter 345 * settings and retains backwards compatability with pre 4.5 functionality. 346 */ 347 if ( is_callable( array( $this->image, 'resizeImage' ) ) && $filter ) { 348 $this->image->setOption( 'filter:support', '2.0' ); 349 $this->image->resizeImage( $dst_w, $dst_h, $filter, 1 ); 350 } else { 351 $this->image->scaleImage( $dst_w, $dst_h ); 352 } 347 353 348 354 // Set appropriate quality settings after resizing. 349 355 if ( 'image/jpeg' == $this->mime_type ) { 350 $this->image->unsharpMaskImage( 0.25, 0.25, 8, 0.065 ); 356 if ( is_callable( array( $this->image, 'unsharpMaskImage' ) ) ) { 357 $this->image->unsharpMaskImage( 0.25, 0.25, 8, 0.065 ); 358 } 359 351 360 $this->image->setOption( 'jpeg:fancy-upsampling', 'off' ); 352 361 } 353 362 … … class WP_Image_Editor_Imagick extends WP_Image_Editor { 364 373 * Note that Imagick::getImageAlphaChannel() is only available if Imagick 365 374 * has been compiled against ImageMagick version 6.4.0 or newer. 366 375 */ 367 if ( method_exists( $this->image, 'getImageAlphaChannel') && $this->image->getImageAlphaChannel() === Imagick::ALPHACHANNEL_UNDEFINED) {376 if ( is_callable( array( $this->image, 'getImageAlphaChannel' ) ) && $this->image->getImageAlphaChannel() === Imagick::ALPHACHANNEL_UNDEFINED && is_callable( array( $this->image, 'setImageAlphaChannel' ) ) ) { 368 377 $this->image->setImageAlphaChannel( Imagick::ALPHACHANNEL_OPAQUE ); 369 378 } 370 379 371 380 // Limit the bit depth of resized images to 8 bits per channel. 372 if ( 8 < $this->image->getImageDepth() ) {381 if ( is_callable( array( $this->image, 'getImageDepth' ) ) && 8 < $this->image->getImageDepth() && is_callable( array( $this->image, 'setImageDepth' ) ) ) { 373 382 $this->image->setImageDepth( 8 ); 374 383 } 375 384 376 $this->image->setInterlaceScheme( Imagick::INTERLACE_NO ); 385 if ( is_callable( array( $this->image, 'setInterlaceScheme' ) ) && defined( 'Imagick::INTERLACE_NO' ) ) { 386 $this->image->setInterlaceScheme( Imagick::INTERLACE_NO ); 387 } 377 388 378 389 } 379 390 catch ( Exception $e ) { … … class WP_Image_Editor_Imagick extends WP_Image_Editor { 662 673 * @return true|WP_Error True if stripping metadata was successful. WP_Error object on error. 663 674 */ 664 675 protected function strip_meta() { 676 /** 677 * Protect a few profiles from being stripped for the following reasons: 678 * 679 * - icc: Color profile information 680 * - iptc: Copyright data 681 * - exif: Orientation data 682 * - xmp: Rights usage data 683 */ 684 $protected_profiles = array( 685 'icc', 686 'iptc', 687 'exif', 688 'xmp' 689 ); 690 665 691 try { 666 692 // Strip profiles. 667 693 foreach ( $this->image->getImageProfiles( '*', true ) as $key => $value ) { 668 if ( $key != 'icc' && $key != 'icm') {694 if ( ! in_array( $key, $protected_profiles ) && is_callable( array( $this->image, 'removeImageProfile' ) ) ) { 669 695 $this->image->removeImageProfile( $key ); 670 696 } 671 697 } 672 698 673 // Strip image properties.674 if ( method_exists( $this->image, 'deleteImageProperty' ) ) {675 $this->image->deleteImageProperty( 'comment' );676 $this->image->deleteImageProperty( 'Thumb::URI' );677 $this->image->deleteImageProperty( 'Thumb::MTime' );678 $this->image->deleteImageProperty( 'Thumb::Size' );679 $this->image->deleteImageProperty( 'Thumb::Mimetype' );680 $this->image->deleteImageProperty( 'software' );681 $this->image->deleteImageProperty( 'Thumb::Image::Width' );682 $this->image->deleteImageProperty( 'Thumb::Image::Height' );683 $this->image->deleteImageProperty( 'Thumb::Document::Pages' );684 } else {685 $this->image->setImageProperty( 'comment', '' );686 $this->image->setImageProperty( 'Thumb::URI', '' );687 $this->image->setImageProperty( 'Thumb::MTime', '' );688 $this->image->setImageProperty( 'Thumb::Size', '' );689 $this->image->setImageProperty( 'Thumb::Mimetype', '' );690 $this->image->setImageProperty( 'software', '' );691 $this->image->setImageProperty( 'Thumb::Image::Width', '' );692 $this->image->setImageProperty( 'Thumb::Image::Height', '' );693 $this->image->setImageProperty( 'Thumb::Document::Pages', '' );694 }695 699 } catch ( Exception $e ) { 696 700 return new WP_Error( 'image_strip_meta_error', $e->getMessage() ); 697 701 }