[wp-trac] [WordPress Trac] #23039: WP_Image_Editor_GD does not preserve alpha if is not resized

WordPress Trac noreply at wordpress.org
Fri Dec 21 20:00:13 UTC 2012


#23039: WP_Image_Editor_GD does not preserve alpha if is not resized
-----------------------------+--------------------------
 Reporter:  joehoyle         |       Type:  defect (bug)
   Status:  new              |   Priority:  normal
Milestone:  Awaiting Review  |  Component:  Media
  Version:  3.5              |   Severity:  normal
 Keywords:                   |
-----------------------------+--------------------------
 If I do something like:


 {{{
 $wp_image_editor_gd->load( $file ) /* $file is a transparent 5px x 5px
 image) */
 $wp_image_editor_gd->resize( 5, 5 ); /* or don't even call resize at all
 */
 $wp_image_editor_gd->save( $new_filepath );
 }}}

 Then the saved file will be stripped of its transparency. This is because
 for image alpha to be preserved, the GD resource has to be passed to
 `wp_imagecreatetruecolor` and it is only passed to that is the resize is
 smaller is not equal to the original dimensions. The same goes for crop()
 etc.

 It's best to see this here: http://core.trac.wordpress.org/browser/trunk
 /wp-includes/class-wp-image-editor-gd.php#L137 , the alpha only preserved
 it it hits http://core.trac.wordpress.org/browser/trunk/wp-includes/class-
 wp-image-editor-gd.php#L161

 If this is not a known issue I can write a patch and unit tests for it.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/23039>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list