| | 545 | |
| | 546 | /** |
| | 547 | * @ticket 39216 |
| | 548 | */ |
| | 549 | public function test_remove_alpha_pdf_preview() { |
| | 550 | if ( ! wp_image_editor_supports( array( 'mime_type' => 'application/pdf' ) ) ) { |
| | 551 | $this->markTestSkipped( 'Rendering PDFs is not supported on this system.' ); |
| | 552 | } |
| | 553 | |
| | 554 | $test_file = DIR_TESTDATA . '/images/test_alpha.pdf'; |
| | 555 | $attachment_id = $this->factory->attachment->create_upload_object( $test_file ); |
| | 556 | $this->assertNotEmpty( $attachment_id ); |
| | 557 | |
| | 558 | $attached_file = get_attached_file( $attachment_id ); |
| | 559 | $this->assertNotEmpty( $attached_file ); |
| | 560 | |
| | 561 | $check = image_get_intermediate_size( $attachment_id, 'thumbnail' ); |
| | 562 | $this->assertNotEmpty( $check['file'] ); |
| | 563 | $check_file = path_join( dirname( $attached_file ), $check['file'] ); |
| | 564 | |
| | 565 | $rgb = array( 'r' => true, 'g' => true, 'b' => true ); // Used for intersecting - not interested in alpha channel. |
| | 566 | $imagick = new Imagick( $check_file ); |
| | 567 | $expected = array( 'r' => 1, 'g' => 1, 'b' => 1 ); // White. |
| | 568 | $output = array_map( 'round', array_intersect_key( $imagick->getImagePixelColor( 1, 1 )->getColor( true /*normalized*/ ), $rgb ) ); |
| | 569 | $this->assertEquals( $expected, $output ); // Allow for floating point equivalence. |
| | 570 | $imagick->destroy(); |
| | 571 | |
| | 572 | $check = image_get_intermediate_size( $attachment_id, 'full' ); |
| | 573 | $this->assertNotEmpty( $check['file'] ); |
| | 574 | $check_file = path_join( dirname( $attached_file ), $check['file'] ); |
| | 575 | |
| | 576 | $imagick = new Imagick( $check_file ); |
| | 577 | $expected = array( 'r' => 1, 'g' => 1, 'b' => 1 ); // White. |
| | 578 | $output = array_map( 'round', array_intersect_key( $imagick->getImagePixelColor( 100, 100 )->getColor( true /*normalized*/ ), $rgb ) ); |
| | 579 | $this->assertEquals( $expected, $output ); // Allow for floating point equivalence. |
| | 580 | $imagick->destroy(); |
| | 581 | } |
| | 582 | |
| | 583 | /** |
| | 584 | * @ticket 39216 |
| | 585 | */ |
| | 586 | public function test_convert_cmyk_pdf_preview() { |
| | 587 | if ( ! wp_image_editor_supports( array( 'mime_type' => 'application/pdf' ) ) ) { |
| | 588 | $this->markTestSkipped( 'Rendering PDFs is not supported on this system.' ); |
| | 589 | } |
| | 590 | |
| | 591 | $test_file = DIR_TESTDATA . '/images/test_cmyk.pdf'; |
| | 592 | $attachment_id = $this->factory->attachment->create_upload_object( $test_file ); |
| | 593 | $this->assertNotEmpty( $attachment_id ); |
| | 594 | |
| | 595 | $attached_file = get_attached_file( $attachment_id ); |
| | 596 | $this->assertNotEmpty( $attached_file ); |
| | 597 | |
| | 598 | $check = image_get_intermediate_size( $attachment_id, 'thumbnail' ); |
| | 599 | $this->assertNotEmpty( $check['file'] ); |
| | 600 | $check_file = path_join( dirname( $attached_file ), $check['file'] ); |
| | 601 | |
| | 602 | // Use GD as Imagick seems to do some color mapping of CMYK images. |
| | 603 | $gd_image = imagecreatefromjpeg( $check_file ); |
| | 604 | // Not sure how system-independent this is. |
| | 605 | // Pixel (15, 10) should be white. |
| | 606 | $output = dechex( imagecolorat( $gd_image, 15, 10 ) ); |
| | 607 | imagedestroy( $gd_image ); |
| | 608 | $this->assertSame( 'ffffff', $output ); |
| | 609 | } |