Make WordPress Core

Changeset 42792 for trunk


Ignore:
Timestamp:
03/07/2018 01:18:08 AM (9 years ago)
Author:
mikeschroder
Message:

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.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/image.php

    r42780 r42792  
    254254                        } else {
    255255                                // Force thumbnails to be soft crops.
    256                                 if ( ! 'thumbnail' === $s ) {
     256                                if ( 'thumbnail' !== $s ) {
    257257                                        $sizes[ $s ]['crop'] = get_option( "{$s}_crop" );
    258258                                }
  • trunk/tests/phpunit/tests/image/functions.php

    r42780 r42792  
    445445
    446446        /**
     447         * Crop setting for PDF.
     448         *
     449         * @ticket 43226
     450         */
     451        public function test_crop_setting_for_pdf() {
     452
     453                if ( ! wp_image_editor_supports( array( 'mime_type' => 'application/pdf' ) ) ) {
     454                        $this->markTestSkipped( 'Rendering PDFs is not supported on this system.' );
     455                }
     456
     457                update_option( 'medium_crop', 1 );
     458
     459                $orig_file = DIR_TESTDATA . '/images/wordpress-gsoc-flyer.pdf';
     460                $test_file = get_temp_dir() . 'wordpress-gsoc-flyer.pdf';
     461                copy( $orig_file, $test_file );
     462
     463                $attachment_id = $this->factory->attachment->create_object(
     464                        $test_file, 0, array(
     465                                'post_mime_type' => 'application/pdf',
     466                        )
     467                );
     468
     469                $this->assertNotEmpty( $attachment_id );
     470
     471                $expected = array(
     472                        'sizes' => array(
     473                                'thumbnail' => array(
     474                                        'file'      => 'wordpress-gsoc-flyer-pdf-116x150.jpg',
     475                                        'width'     => 116,
     476                                        'height'    => 150,
     477                                        'mime-type' => 'image/jpeg',
     478                                ),
     479                                'medium'    => array(
     480                                        'file'      => 'wordpress-gsoc-flyer-pdf-300x300.jpg',
     481                                        'width'     => 300,
     482                                        'height'    => 300,
     483                                        'mime-type' => 'image/jpeg',
     484                                ),
     485                                'large'     => array(
     486                                        'file'      => 'wordpress-gsoc-flyer-pdf-791x1024.jpg',
     487                                        'width'     => 791,
     488                                        'height'    => 1024,
     489                                        'mime-type' => 'image/jpeg',
     490                                ),
     491                                'full'      => array(
     492                                        'file'      => 'wordpress-gsoc-flyer-pdf.jpg',
     493                                        'width'     => 1088,
     494                                        'height'    => 1408,
     495                                        'mime-type' => 'image/jpeg',
     496                                ),
     497                        ),
     498                );
     499
     500                $metadata = wp_generate_attachment_metadata( $attachment_id, $test_file );
     501                $this->assertSame( $expected, $metadata );
     502
     503                unlink( $test_file );
     504                foreach ( $metadata['sizes'] as $size ) {
     505                        unlink( get_temp_dir() . $size['file'] );
     506                }
     507        }
     508
     509        /**
    447510         * @ticket 39231
    448511         */
Note: See TracChangeset for help on using the changeset viewer.