WordPress.org

Make WordPress Core

Changeset 39303


Ignore:
Timestamp:
11/18/2016 10:21:19 PM (20 months ago)
Author:
mikeschroder
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-image-editor-imagick.php

    r39187 r39303  
    150150            $filename = $this->file;
    151151
    152             // By default, PDFs are rendered in a very low resolution.
    153             // We want the thumbnail to be readable, so increase the rendering dpi.
    154152            if ( 'pdf' == strtolower( $file_parts['extension'] ) ) {
    155                 $this->image->setResolution( 128, 128 );
    156 
    157                 // Only load the first page.
    158                 $filename .= '[0]';
     153                $filename = $this->pdf_setup();
    159154            }
    160155
     
    744739    }
    745740
     741    /**
     742     * Sets up Imagick for PDF processing.
     743     * Increases rendering DPI and only loads first page.
     744     *
     745     * @since 4.7.0
     746     * @access protected
     747     *
     748     * @return string|WP_Error File to load or WP_Error on failure.
     749     */
     750    protected function pdf_setup() {
     751        try {
     752            // By default, PDFs are rendered in a very low resolution.
     753            // We want the thumbnail to be readable, so increase the rendering DPI.
     754            $this->image->setResolution( 128, 128 );
     755
     756            // Only load the first page.
     757            return $this->file . '[0]';
     758        }
     759        catch ( Exception $e ) {
     760            return new WP_Error( 'pdf_setup_failed', $e->getMessage(), $this->file );
     761        }
     762    }
     763
    746764}
Note: See TracChangeset for help on using the changeset viewer.