Changeset 49174
- Timestamp:
- 10/16/2020 10:46:58 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-image-editor-imagick.php
r48798 r49174 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(); 147 } 148 149 // Reading image after Imagick instantiation because `setResolution` 150 // only applies correctly before the image is read. 151 $this->image->readImage( $filename ); 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 ); 152 } 152 153 153 154 if ( ! $this->image->valid() ) { … … 166 167 167 168 $updated_size = $this->update_size(); 169 168 170 if ( is_wp_error( $updated_size ) ) { 169 171 return $updated_size; … … 796 798 $this->image->setResolution( 128, 128 ); 797 799 800 // Only load the first page. 801 return $this->file . '[0]'; 802 } catch ( Exception $e ) { 803 return new WP_Error( 'pdf_setup_failed', $e->getMessage(), $this->file ); 804 } 805 } 806 807 /** 808 * Load the image produced by Ghostscript. 809 * 810 * Includes a workaround for a bug in Ghostscript 8.70 that prevents processing of some PDF files 811 * when `use-cropbox` is set. 812 * 813 * @since 5.6 814 * 815 * @return true|WP_error 816 */ 817 protected function pdf_load_source() { 818 $filename = $this->pdf_setup(); 819 820 if ( is_wp_error( $filename ) ) { 821 return $filename; 822 } 823 824 try { 798 825 // When generating thumbnails from cropped PDF pages, Imagemagick uses the uncropped 799 826 // area (resulting in unnecessary whitespace) unless the following option is set. 800 827 $this->image->setOption( 'pdf:use-cropbox', true ); 801 828 802 // Only load the first page. 803 return $this->file . '[0]'; 804 } catch ( Exception $e ) { 805 return new WP_Error( 'pdf_setup_failed', $e->getMessage(), $this->file ); 806 } 829 // Reading image after Imagick instantiation because `setResolution` 830 // only applies correctly before the image is read. 831 $this->image->readImage( $filename ); 832 } catch ( Exception $e ) { 833 // Attempt to run `gs` without the `use-cropbox` option. See #48853. 834 $this->image->setOption( 'pdf:use-cropbox', false ); 835 836 $this->image->readImage( $filename ); 837 } 838 839 return true; 807 840 } 808 841
Note: See TracChangeset
for help on using the changeset viewer.