WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/26/2016 07:27:51 AM (3 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/src/wp-includes/class-wp-image-editor-imagick.php

    r38015 r38949  
    7474            'flipimage',
    7575            'flopimage',
     76            'readimage',
    7677        );
    7778
     
    145146
    146147        try {
    147             $this->image = new Imagick( $this->file );
     148            $this->image = new Imagick();
     149            $file_parts = pathinfo( $this->file );
     150
     151            // By default, PDFs are rendered in a very low resolution.
     152            // We want the thumbnail to be readable, so increase the rendering dpi.
     153            if ( 'pdf' == strtolower( $file_parts['extension'] ) ) {
     154                $this->image->setResolution( 128, 128 );
     155            }
     156
     157            // Reading image after Imagick instantiation because `setResolution`
     158            // only applies correctly before the image is read.
     159            $this->image->readImage( $this->file );
    148160
    149161            if ( ! $this->image->valid() )
Note: See TracChangeset for help on using the changeset viewer.