Ticket #39216: 39216.patch
| File 39216.patch, 3.7 KB (added by , 9 years ago) |
|---|
-
src/wp-includes/class-wp-image-editor-imagick.php
146 146 147 147 try { 148 148 $this->image = new Imagick(); 149 $ file_parts = pathinfo( $this->file);149 $is_pdf = 'pdf' === strtolower( pathinfo( $this->file, PATHINFO_EXTENSION ) ); 150 150 $filename = $this->file; 151 151 152 if ( 'pdf' == strtolower( $file_parts['extension'] )) {152 if ( $is_pdf ) { 153 153 $filename = $this->pdf_setup(); 154 154 } 155 155 … … 164 164 if ( is_callable( array( $this->image, 'setIteratorIndex' ) ) ) 165 165 $this->image->setIteratorIndex(0); 166 166 167 if ( $is_pdf ) { 168 $this->pdf_process(); 169 } 170 167 171 $this->mime_type = $this->get_mime_type( $this->image->getImageFormat() ); 168 172 } 169 173 catch ( Exception $e ) { … … 761 765 } 762 766 } 763 767 768 /** 769 * Process PDF after it's been read. 770 * Remove alpha channel to avoid black backgrounds. 771 * 772 * @since 4.x 773 * @access protected 774 * 775 * @return void 776 */ 777 protected function pdf_process() { 778 // Remove alpha channel if possible to avoid black backgrounds. RemoveAlphaChannel added in ImageMagick 6.7.5. 779 $version = Imagick::getVersion(); 780 if ( $version['versionNumber'] >= 0x675 ) { 781 try { 782 // Imagick::ALPHACHANNEL_REMOVE mapped to RemoveAlphaChannel in PHP imagick 3.2.0b2. 783 // Value seems to have remained stable at 12 for ImageMagick 6.7.5 to 7.0 (although other AlphaChannelType enum values have changed). 784 $this->image->setImageAlphaChannel( defined( 'Imagick::ALPHACHANNEL_REMOVE' ) ? Imagick::ALPHACHANNEL_REMOVE : 12 ); 785 } 786 catch ( Exception $e ) { 787 // Ignore. 788 } 789 } 790 } 764 791 } -
tests/phpunit/tests/image/editor_imagick.php
531 531 $this->assertImageAlphaAtPointImagick( $save_to_file, array( 0, 0 ), $pre_rotate_alpha ); 532 532 unlink( $save_to_file ); 533 533 } 534 535 /** 536 * @ticket 39216 537 */ 538 public function test_remove_alpha_pdf_preview() { 539 if ( ! wp_image_editor_supports( array( 'mime_type' => 'application/pdf' ) ) ) { 540 $this->markTestSkipped( 'Rendering PDFs is not supported on this system.' ); 541 } 542 543 $test_file = 'test_alpha.pdf'; 544 $test_path = DIR_TESTDATA . '/images/' . $test_file; 545 $attachment_id = $this->factory->attachment->create_upload_object( $test_path ); 546 $this->assertNotEmpty( $attachment_id ); 547 548 $attached_file = get_attached_file( $attachment_id ); 549 $this->assertNotEmpty( $attached_file ); 550 551 $check = image_get_intermediate_size( $attachment_id, 'thumbnail' ); 552 $this->assertNotEmpty( $check['file'] ); 553 $check_file = str_replace( $test_file, $check['file'], $attached_file ); 554 555 $imagick = new Imagick( $check_file ); 556 $expected = array( 'r' => 1, 'g' => 1, 'b' => 1, 'a' => 1 ); // White. 557 $output = array_map( 'ceil', $imagick->getImagePixelColor( 1, 1 )->getColor( true /*normalized*/ ) ); 558 $this->assertEquals( $expected, $output ); // Allow for floating point equivalence. 559 $imagick->destroy(); 560 561 $check = image_get_intermediate_size( $attachment_id, 'full' ); 562 $this->assertNotEmpty( $check['file'] ); 563 $check_file = str_replace( $test_file, $check['file'], $attached_file ); 564 565 $imagick = new Imagick( $check_file ); 566 $expected = array( 'r' => 1, 'g' => 1, 'b' => 1, 'a' => 1 ); // White. 567 $output = array_map( 'ceil', $imagick->getImagePixelColor( 100, 100 )->getColor( true /*normalized*/ ) ); 568 $this->assertEquals( $expected, $output ); // Allow for floating point equivalence. 569 $imagick->destroy(); 570 } 534 571 }