From 28e538bf805b95f3d8f7c4c58015d2f132ab2747 Mon Sep 17 00:00:00 2001 From: Mike Schroder Date: Wed, 9 Nov 2016 21:04:04 +0000 Subject: [PATCH] Media: Only load first PDF page for thumbnails. To improve performance, directly load the first page of uploaded PDFs to reduce the total clock time necessary to generate thumbnails. Props dglingren, lukecavanagh, helen, johnbillion, mikeschroder. See #38522. git-svn-id: https://develop.svn.wordpress.org/trunk@39187 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-image-editor-imagick.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/class-wp-image-editor-imagick.php b/src/wp-includes/class-wp-image-editor-imagick.php index fb56eb15cf..c89706cd58 100644 --- a/src/wp-includes/class-wp-image-editor-imagick.php +++ b/src/wp-includes/class-wp-image-editor-imagick.php @@ -147,16 +147,20 @@ class WP_Image_Editor_Imagick extends WP_Image_Editor { try { $this->image = new Imagick(); $file_parts = pathinfo( $this->file ); + $filename = $this->file; // By default, PDFs are rendered in a very low resolution. // We want the thumbnail to be readable, so increase the rendering dpi. if ( 'pdf' == strtolower( $file_parts['extension'] ) ) { $this->image->setResolution( 128, 128 ); + + // Only load the first page. + $filename .= '[0]'; } // Reading image after Imagick instantiation because `setResolution` // only applies correctly before the image is read. - $this->image->readImage( $this->file ); + $this->image->readImage( $filename ); if ( ! $this->image->valid() ) return new WP_Error( 'invalid_image', __('File is not an image.'), $this->file);