Make WordPress Core


Ignore:
Timestamp:
10/26/2016 07:27:51 AM (7 years ago)
Author:
mikeschroder
Message:

Media: Add support for rendering PDF thumbnails.

When support for PDFs is available, on upload,
render 'Thumbnail', 'Medium', 'Large', and 'Full' sizes of
the first page, and save them in attachment meta.

Use these renders within Add Media, Media Gallery and List views,
Attachment Details, Post/Attachment Edit screens, and Attachment pages.

Support available by default via Imagick -> ImageMagick -> Ghostscript,
but can be provided by any WP_Image_Editor that supports PDFs.

Props adamsilverstein, azaozz, celloexpressions, desrosj, dglingren, ericlewis, ipstenu, joemcgill, joyously, markoheijnen, melchoyce, mikeschroder, tomauger.
Fixes #31050.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/image/functions.php

    r38762 r38949  
    352352        WP_Image_Editor_Mock::$save_return = array();
    353353    }
     354
     355    /**
     356     * @ticket 31050
     357     */
     358    public function test_wp_generate_attachment_metadata_pdf() {
     359        if ( ! wp_image_editor_supports( array( 'mime_type' => 'application/pdf' ) ) ) {
     360            $this->markTestSkipped( 'Rendering PDFs is not supported on this system.' );
     361        }
     362
     363        $orig_file = DIR_TESTDATA . '/images/wordpress-gsoc-flyer.pdf';
     364        $test_file = '/tmp/wordpress-gsoc-flyer.pdf';
     365        copy( $orig_file, $test_file );
     366
     367        $attachment_id = $this->factory->attachment->create_object( $test_file, 0, array(
     368            'post_mime_type' => 'application/pdf',
     369        ) );
     370
     371        $this->assertNotEmpty( $attachment_id );
     372
     373        $expected = array(
     374            'sizes' => array(
     375                'thumbnail' => array(
     376                    'file'      => "wordpress-gsoc-flyer-116x150.jpg",
     377                    'width'     => 116,
     378                    'height'    => 150,
     379                    'mime-type' => "image/jpeg",
     380                ),
     381                'medium'    => array(
     382                    'file'      => "wordpress-gsoc-flyer-232x300.jpg",
     383                    'width'     => 232,
     384                    'height'    => 300,
     385                    'mime-type' => "image/jpeg",
     386                ),
     387                'large'     => array(
     388                    'file'      => "wordpress-gsoc-flyer-791x1024.jpg",
     389                    'width'     => 791,
     390                    'height'    => 1024,
     391                    'mime-type' => "image/jpeg",
     392                ),
     393                'full'      => array(
     394                    'file'      => "wordpress-gsoc-flyer.jpg",
     395                    'width'     => 1088,
     396                    'height'    => 1408,
     397                    'mime-type' => "image/jpeg",
     398                ),
     399            ),
     400        );
     401
     402        $metadata = wp_generate_attachment_metadata( $attachment_id, $test_file );
     403        $this->assertSame( $expected, $metadata );
     404
     405        unlink( $test_file );
     406    }
    354407}
Note: See TracChangeset for help on using the changeset viewer.