diff --git a/src/wp-admin/includes/image.php b/src/wp-admin/includes/image.php index 573f107605..d6e6fbd563 100644 --- a/src/wp-admin/includes/image.php +++ b/src/wp-admin/includes/image.php @@ -253,7 +253,7 @@ function wp_generate_attachment_metadata( $attachment_id, $file ) { $sizes[ $s ]['crop'] = $_wp_additional_image_sizes[ $s ]['crop']; } else { // Force thumbnails to be soft crops. - if ( ! 'thumbnail' === $s ) { + if ( 'thumbnail' !== $s ) { $sizes[ $s ]['crop'] = get_option( "{$s}_crop" ); } } diff --git a/tests/phpunit/tests/image/functions.php b/tests/phpunit/tests/image/functions.php index 915b695b42..913fefd93d 100644 --- a/tests/phpunit/tests/image/functions.php +++ b/tests/phpunit/tests/image/functions.php @@ -443,6 +443,69 @@ class Tests_Image_Functions extends WP_UnitTestCase { } } + /** + * Crop setting for PDF. + * + * @ticket 43226 + */ + public function test_crop_setting_for_pdf() { + + if ( ! wp_image_editor_supports( array( 'mime_type' => 'application/pdf' ) ) ) { + $this->markTestSkipped( 'Rendering PDFs is not supported on this system.' ); + } + + update_option( 'medium_crop', 1 ); + + $orig_file = DIR_TESTDATA . '/images/wordpress-gsoc-flyer.pdf'; + $test_file = get_temp_dir() . 'wordpress-gsoc-flyer.pdf'; + copy( $orig_file, $test_file ); + + $attachment_id = $this->factory->attachment->create_object( + $test_file, 0, array( + 'post_mime_type' => 'application/pdf', + ) + ); + + $this->assertNotEmpty( $attachment_id ); + + $expected = array( + 'sizes' => array( + 'thumbnail' => array( + 'file' => 'wordpress-gsoc-flyer-pdf-116x150.jpg', + 'width' => 116, + 'height' => 150, + 'mime-type' => 'image/jpeg', + ), + 'medium' => array( + 'file' => 'wordpress-gsoc-flyer-pdf-300x300.jpg', + 'width' => 300, + 'height' => 300, + 'mime-type' => 'image/jpeg', + ), + 'large' => array( + 'file' => 'wordpress-gsoc-flyer-pdf-791x1024.jpg', + 'width' => 791, + 'height' => 1024, + 'mime-type' => 'image/jpeg', + ), + 'full' => array( + 'file' => 'wordpress-gsoc-flyer-pdf.jpg', + 'width' => 1088, + 'height' => 1408, + 'mime-type' => 'image/jpeg', + ), + ), + ); + + $metadata = wp_generate_attachment_metadata( $attachment_id, $test_file ); + $this->assertSame( $expected, $metadata ); + + unlink( $test_file ); + foreach ( $metadata['sizes'] as $size ) { + unlink( get_temp_dir() . $size['file'] ); + } + } + /** * @ticket 39231 */