[wp-trac] [WordPress Trac] #48202: Media: rotation of JPEG files may fail

WordPress Trac noreply at wordpress.org
Thu Oct 3 15:08:10 UTC 2019


#48202: Media: rotation of JPEG files may fail
--------------------------+--------------------
 Reporter:  azaozz        |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  high          |  Milestone:  5.3
Component:  Media         |    Version:
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+--------------------
 Reported by @tmatsuur at
 https://core.trac.wordpress.org/ticket/14459#comment:98.

 In an environment where GD is used, JPEG files could not be rotated.

 This is due to improper processing of JPEG images that do not support the
 alpha channel.

 class-wp-image-editor-gd.php: 344 (5.3 Beta 2)

 {{{
 public function rotate( $angle ) {
         if ( function_exists( 'imagerotate' ) ) {
                 $transparency = imagecolorallocatealpha( $this->image,
 255, 255, 255, 127 );
                 $rotated      = imagerotate( $this->image, $angle,
 $transparency );

                 if ( is_resource( $rotated ) ) {
                         imagealphablending( $rotated, true );
                         imagesavealpha( $rotated, true );
                         imagedestroy( $this->image );
                         $this->image = $rotated;
                         $this->update_size();
                         return true;
                 }
         }
         return new WP_Error( 'image_rotate_error', __( 'Image rotate
 failed.' ), $this->file );
 }
 }}}

 I confirmed that the JPEG image can be rotated normally by correcting as
 follows.

 {{{
 public function rotate( $angle ) {
         if ( function_exists( 'imagerotate' ) ) {
                 if ( 'image/png' === $this->mime_type || 'image/gif' ===
 $this->mime_type ) {
                         $transparency = imagecolorallocatealpha(
 $this->image, 255, 255, 255, 127 );
                         $rotated      = imagerotate( $this->image, $angle,
 $transparency );

                         if ( is_resource( $rotated ) ) {
                                 imagealphablending( $rotated, true );
                                 imagesavealpha( $rotated, true );
                                 imagedestroy( $this->image );
                                 $this->image = $rotated;
                                 $this->update_size();
                                 return true;
                         }
                 } else {
                         $rotated      = imagerotate( $this->image, $angle
 );
                         if ( is_resource( $rotated ) ) {
                                 $this->image = $rotated;
                                 $this->update_size();
                                 return true;
                         }
                 }
         }
         return new WP_Error( 'image_rotate_error', __( 'Image rotate
 failed.' ), $this->file );
 }
 }}}

 The PHP version that confirmed this behavior is 7.2.3.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/48202>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list