[wp-trac] [WordPress Trac] #14459: Rotate Full Size Images on Upload

WordPress Trac noreply at wordpress.org
Thu Oct 3 08:21:30 UTC 2019


#14459: Rotate Full Size Images on Upload
-------------------------------------------------+-------------------------
 Reporter:  mrroundhill                          |       Owner:
                                                 |  mikeschroder
     Type:  enhancement                          |      Status:  closed
 Priority:  normal                               |   Milestone:  5.3
Component:  Media                                |     Version:  3.0
 Severity:  normal                               |  Resolution:  fixed
 Keywords:  has-patch needs-testing needs-unit-  |     Focuses:
  tests needs-dev-note                           |
-------------------------------------------------+-------------------------

Comment (by tmatsuur):

 Is this thread already closed?

 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/14459#comment:98>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list