WordPress 4.7 makes it easier to preview PDFs in the media library by generating image representations of the first page, which are now used throughout the media library and media attachment screens.
WP_Image_Editor is available that supports PDF, the following sizes are generated:
- Full size representation, rendered at 128dpi.
- Thumbnail (without cropping)
The sizes generated can be modified, or the feature disabled entirely via the new
fallback_intermediate_image_sizes filter, and are all stored in the
sizes array in attachment meta.
The preview images generated are used within the Media screen, Gallery, Attachment Details, and on the Attachment page for PDFs.
Core support is provided through
WP_Image_Editor_Imagick and requires Imagick, ImageMagick, and Ghostscript support. When not supported, or if the generation fails, WordPress falls back to previous behavior and saves the attachment without adding image previews to meta.
For more context, see #31050 for the primary ticket and #38594 for the filter.
Since this change requires having Imagick load only the first page of a PDF for performance reasons, this means that if you rely on core loading the entire PDF for your extension of
WP_Image_Editor_Imagick, this will no longer function as expected (See: #38832).
As a result, in , the PDF setup code was moved to
WP_Image_Editor_Imagick->pdf_setup(), which can be overridden to restore the previous behavior if needed.