Make WordPress Core

Ticket #39331: 39331.patch

File 39331.patch, 1.7 KB (added by gitlost, 8 years ago)

Don't call unsharpMaskImage() if CMYK color space.

  • src/wp-includes/class-wp-image-editor-imagick.php

     
    367367
    368368                        // Set appropriate quality settings after resizing.
    369369                        if ( 'image/jpeg' == $this->mime_type ) {
    370                                 if ( is_callable( array( $this->image, 'unsharpMaskImage' ) ) ) {
     370                                // Not compatible with CMYK color spaces.
     371                                if ( is_callable( array( $this->image, 'unsharpMaskImage' ) && Imagick::COLORSPACE_CMYK !== $this->image->getImageColorspace() ) ) {
    371372                                        $this->image->unsharpMaskImage( 0.25, 0.25, 8, 0.065 );
    372373                                }
    373374
  • tests/phpunit/tests/image/editor_imagick.php

     
    542542
    543543                $this->assertTrue( $result );
    544544        }
     545
     546        /**
     547         * @ticket 39331
     548         */
     549        public function test_cmyk_jpg_resize() {
     550                $test_file = DIR_TESTDATA . '/images/test_cmyk.jpg';
     551                $save_to_file = tempnam( get_temp_dir(), '' ) . '.jpg';
     552
     553                $editor = new WP_Image_Editor_Imagick( $test_file );
     554                $editor->load();
     555                $editor->resize( 106, 150 ); // Default thumbnail size.
     556                $editor->save( $save_to_file );
     557
     558                // Use GD as Imagick seems to do some color mapping of CMYK images.
     559                $gd_image = imagecreatefromjpeg( $save_to_file );
     560                // Not sure how system-independent this is.
     561                // Pixel (15, 10) should be white.
     562                $output = dechex( imagecolorat( $gd_image, 15, 10 ) );
     563                imagedestroy( $gd_image );
     564                $this->assertSame( 'ffffff', $output );
     565
     566                unlink( $save_to_file );
     567        }
    545568}