Media: Allow override of PDF setup for multiple pages or DPI.
After [39187], WordPress started loading only the first page of a PDF. This is appropriate for performance, but made it impossible to write plugins that read other pages without overriding `load()`. Introduces `WP_Image_Editor_Imagick->pdf_setup()`, to allow an override to change WordPress' rendering DPI defaults or which pages are loaded. Fixes #38832. See #38522, #31050. Props markoheijnen, joemcgill, mikeschroder. git-svn-id: https://develop.svn.wordpress.org/trunk@39303 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
aa4af7839e
commit
0ab17d2158
@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user