Media: Correctly allow changing PDF thumbnail crop value.
Corrects logic that keeping plugins from setting crop value of intermediate image sizes for rendered PDFs. Adds test. Props leemon, SergeyBiryukov, chetan200891, birgire. Fixes #43226. git-svn-id: https://develop.svn.wordpress.org/trunk@42792 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
0005ad91d6
commit
3a46cba430
@ -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" );
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user