diff --git a/src/wp-includes/class-wp-image-editor-imagick.php b/src/wp-includes/class-wp-image-editor-imagick.php index c89706cd58..fc6fc933ae 100644 --- a/src/wp-includes/class-wp-image-editor-imagick.php +++ b/src/wp-includes/class-wp-image-editor-imagick.php @@ -149,13 +149,8 @@ class WP_Image_Editor_Imagick extends WP_Image_Editor { $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]'; + $filename = $this->pdf_setup(); } // Reading image after Imagick instantiation because `setResolution` @@ -743,4 +738,27 @@ class WP_Image_Editor_Imagick extends WP_Image_Editor { return true; } + /** + * Sets up Imagick for PDF processing. + * Increases rendering DPI and only loads first page. + * + * @since 4.7.0 + * @access protected + * + * @return string|WP_Error File to load or WP_Error on failure. + */ + protected function pdf_setup() { + try { + // By default, PDFs are rendered in a very low resolution. + // We want the thumbnail to be readable, so increase the rendering DPI. + $this->image->setResolution( 128, 128 ); + + // Only load the first page. + return $this->file . '[0]'; + } + catch ( Exception $e ) { + return new WP_Error( 'pdf_setup_failed', $e->getMessage(), $this->file ); + } + } + }