WP_Image_Editor_Imagick::pdf_load_source() WordPress Method

This function loads a PDF document into an Imagick object for further editing. PDF documents can be loaded into Imagick objects using the WP_Image_Editor_Imagick::pdf_load_source() function. This function supports loading PDFs from either a file or a URL. Once the PDF has been loaded, it can be edited using the various methods provided by the Imagick class.

WP_Image_Editor_Imagick::pdf_load_source() #

Load the image produced by Ghostscript.


Description

Includes a workaround for a bug in Ghostscript 8.70 that prevents processing of some PDF files when use-cropbox is set.


Top ↑

Return

(true|WP_Error)


Top ↑

Source

File: wp-includes/class-wp-image-editor-imagick.php

907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
protected function pdf_load_source() {
    $filename = $this->pdf_setup();
 
    if ( is_wp_error( $filename ) ) {
        return $filename;
    }
 
    try {
        // When generating thumbnails from cropped PDF pages, Imagemagick uses the uncropped
        // area (resulting in unnecessary whitespace) unless the following option is set.
        $this->image->setOption( 'pdf:use-cropbox', true );
 
        // Reading image after Imagick instantiation because `setResolution`
        // only applies correctly before the image is read.
        $this->image->readImage( $filename );
    } catch ( Exception $e ) {
        // Attempt to run `gs` without the `use-cropbox` option. See #48853.
        $this->image->setOption( 'pdf:use-cropbox', false );
 
        $this->image->readImage( $filename );
    }
 
    return true;
}


Top ↑

Changelog

Changelog
VersionDescription
5.6.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by the Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.