WP_Image_Editor_Imagick::pdf_load_source
Load the image produced by Ghostscript.
Includes a workaround for a bug in Ghostscript 8.70 that prevents processing of some PDF files when use-cropbox is set.
Method of the class: WP_Image_Editor_Imagick{}
No Hooks.
Returns
true|WP_Error.
Usage
// protected - for code of main (parent) or child class $result = $this->pdf_load_source();
Changelog
| Since 5.6.0 | Introduced. |
WP_Image_Editor_Imagick::pdf_load_source() WP Image Editor Imagick::pdf load source code WP 7.0.4
protected function pdf_load_source() {
$filename = $this->pdf_setup();
if ( is_wp_error( $filename ) ) {
return $filename;
}
foreach ( array( 'true', 'false' ) as $use_cropbox ) {
try {
/**
* When generating thumbnails from cropped PDF pages, Imagemagick uses the uncropped
* area (resulting in unnecessary whitespace) unless the following option is set.
*
* However, it sometimes fails, so if that happens, run it without the option.
*
* @ticket 48853
*/
$this->image->setOption( 'pdf:use-cropbox', $use_cropbox );
/*
* Reading image after Imagick instantiation because `setResolution`
* only applies correctly before the image is read.
*/
if ( is_string( $this->stream_file_data ) ) {
$this->image->setFilename( 'PDF:unknown.pdf[0]' );
$this->image->readImageBlob( $this->stream_file_data, $this->image_given_name );
} else {
$this->image->readImage( $filename );
}
return true;
} catch ( Exception $e ) {
continue;
}
}
return new WP_Error( 'invalid_image', __( 'File is not an image.' ), $this->file );
}