WordPress.org

Make WordPress Core

Ticket #38832: 38832.diff

File 38832.diff, 1.5 KB (added by mikeschroder, 4 years ago)

Workaround. Would allow authors to override the PDF behavior.

  • src/wp-includes/class-wp-image-editor-imagick.php

    diff --git src/wp-includes/class-wp-image-editor-imagick.php src/wp-includes/class-wp-image-editor-imagick.php
    index c89706c..a5fe88f 100644
    class WP_Image_Editor_Imagick extends WP_Image_Editor { 
    149149                        $file_parts = pathinfo( $this->file );
    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
    161156                        // Reading image after Imagick instantiation because `setResolution`
    class WP_Image_Editor_Imagick extends WP_Image_Editor { 
    743738                return true;
    744739        }
    745740
     741        /**
     742         * Set up Imagick for PDF processing.
     743         * Sets resolution and specifies the first page for loading.
     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}