WP_Image_Editor_GD does not preserve alpha if is not resized
|Reported by:||joehoyle||Owned by:|
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.
Change History (27)
comment:21 dh-shredder — 11 months ago
- Keywords close added
- Resolution set to fixed
- Status changed from new to closed