mirror of
https://github.com/WordPress/WordPress.git
synced 2025-01-03 06:57:35 +01:00
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. Built from https://develop.svn.wordpress.org/trunk@39303 git-svn-id: http://core.svn.wordpress.org/trunk@39243 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
0fdb955ce8
commit
e12d3813f0
@ -149,13 +149,8 @@ class WP_Image_Editor_Imagick extends WP_Image_Editor {
|
|||||||
$file_parts = pathinfo( $this->file );
|
$file_parts = pathinfo( $this->file );
|
||||||
$filename = $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'] ) ) {
|
if ( 'pdf' == strtolower( $file_parts['extension'] ) ) {
|
||||||
$this->image->setResolution( 128, 128 );
|
$filename = $this->pdf_setup();
|
||||||
|
|
||||||
// Only load the first page.
|
|
||||||
$filename .= '[0]';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reading image after Imagick instantiation because `setResolution`
|
// Reading image after Imagick instantiation because `setResolution`
|
||||||
@ -743,4 +738,27 @@ class WP_Image_Editor_Imagick extends WP_Image_Editor {
|
|||||||
return true;
|
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 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '4.7-beta4-39302';
|
$wp_version = '4.7-beta4-39303';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
Loading…
Reference in New Issue
Block a user