Ticket #48853: 48853.1.diff
| File 48853.1.diff, 2.6 KB (added by , 6 years ago) |
|---|
-
src/wp-includes/class-wp-image-editor-imagick.php
140 140 try { 141 141 $this->image = new Imagick(); 142 142 $file_extension = strtolower( pathinfo( $this->file, PATHINFO_EXTENSION ) ); 143 $filename = $this->file;144 143 145 144 if ( 'pdf' === $file_extension ) { 146 $filename = $this->pdf_setup(); 145 $pdf_loaded = $this->pdf_load_source(); 146 147 if ( is_wp_error( $pdf_loaded ) ) { 148 return $pdf_loaded; 149 } 150 } else { 151 $this->image->readImage( $this->file ); 147 152 } 148 153 149 // Reading image after Imagick instantiation because `setResolution`150 // only applies correctly before the image is read.151 $this->image->readImage( $filename );152 153 154 if ( ! $this->image->valid() ) { 154 155 return new WP_Error( 'invalid_image', __( 'File is not an image.' ), $this->file ); 155 156 } … … 165 166 } 166 167 167 168 $updated_size = $this->update_size(); 169 168 170 if ( is_wp_error( $updated_size ) ) { 169 171 return $updated_size; 170 172 } … … 794 796 // We want the thumbnail to be readable, so increase the rendering DPI. 795 797 $this->image->setResolution( 128, 128 ); 796 798 799 // Only load the first page. 800 return $this->file . '[0]'; 801 } catch ( Exception $e ) { 802 return new WP_Error( 'pdf_setup_failed', $e->getMessage(), $this->file ); 803 } 804 } 805 806 /** 807 * Load the image produced by Ghostscript. 808 * 809 * Includes a workaround for a bug in Ghostscript 8.7 that may prevent processing of some PDF files 810 * when `use-cropbox` is set. 811 * 812 * @since 5.3.1 813 * 814 * @return true|WP_error 815 */ 816 protected function pdf_load_source() { 817 $filename = $this->pdf_setup(); 818 819 if ( is_wp_error( $filename ) ) { 820 return $filename; 821 } 822 823 try { 797 824 // When generating thumbnails from cropped PDF pages, Imagemagick uses the uncropped 798 825 // area (resulting in unnecessary whitespace) unless the following option is set. 799 826 $this->image->setOption( 'pdf:use-cropbox', true ); 800 827 801 // Only load the first page. 802 return $this->file . '[0]'; 828 // Reading image after Imagick instantiation because `setResolution` 829 // only applies correctly before the image is read. 830 $this->image->readImage( $filename ); 803 831 } catch ( Exception $e ) { 804 return new WP_Error( 'pdf_setup_failed', $e->getMessage(), $this->file ); 832 // Attempt to run `gs` without the `use-cropbox` option. See #48853. 833 $this->image->setOption( 'pdf:use-cropbox', false ); 834 835 $this->image->readImage( $filename ); 805 836 } 837 838 return true; 806 839 } 807 840 808 841 }