Ticket #2805 (closed defect: fixed)

Opened 2 years ago

Last modified 8 months ago

Preserve PNG transparency/alpha during thumbnail creation

Reported by: Libertus Assigned to: westi
Priority: high Milestone: 2.5
Component: Administration Version: 2.1
Severity: major Keywords: has-patch needs-testing
Cc:

Description

PNG images with transparent backgrounds get thumbnails with black backgrounds. This patch to wp_create_thumbmail() fixes that.

Attachments

wp_create_thumbnail-preserve-PNG-transparency.diff (1.2 kB) - added by Libertus on 06/08/06 14:00:34.
the patch
wp_create_thumbnail-preserve-PNG-transparency-ideal.diff (1.3 kB) - added by Libertus on 06/08/06 14:08:46.
same patch but with function return value changed
2805.diff (0.7 kB) - added by Otto42 on 07/30/07 16:15:41.
Simpler patch

Change History

06/08/06 14:00:34 changed by Libertus

  • attachment wp_create_thumbnail-preserve-PNG-transparency.diff added.

the patch

06/08/06 14:08:04 changed by Libertus

My ideal patch incorporates the return value change I mention on #2682

06/08/06 14:08:46 changed by Libertus

  • attachment wp_create_thumbnail-preserve-PNG-transparency-ideal.diff added.

same patch but with function return value changed

07/15/07 18:05:18 changed by Nazgul

  • status changed from new to closed.
  • resolution set to wontfix.

No traction in almost a year, so closing as wontfix.

Feel free to re-open it if you have additional information/suggestions/patches/...

07/29/07 16:01:05 changed by jberthon

  • status changed from closed to reopened.
  • resolution deleted.

I really wish this will be fixed!! This is really sad that WP lost the transparency in the PNG... Why can't it be integrated into WP main code? I have to do and redo the modification at each update!! :-(

After the line 2294 of this file: http://trac.wordpress.org/browser/tags/2.2.1/wp-admin/admin-functions.php add the following lines:

if ( ( $type[2] == 3) AND ( function_exists( 'imagesavealpha' ) ) ) {

imagesavealpha( $thumbnail, TRUE ); $trans_colour = imagecolorallocatealpha($thumbnail, 0, 0, 0, 127); imagefill($thumbnail, 0, 0, $trans_colour);

}

This code was taken from this documentation page: http://fr.php.net/manual/en/function.imagecreatetruecolor.php

07/29/07 16:07:09 changed by foolswisdom

  • milestone set to 2.4 (future).

07/30/07 16:15:41 changed by Otto42

  • attachment 2805.diff added.

Simpler patch

07/30/07 16:17:36 changed by Otto42

  • milestone changed from 2.4 (future) to 2.3 (trunk).

Uploaded a simpler patch which should do the trick for trunk. Somebody test it out.

This does need to be in trunk, IMO. Uploading transparent PNG files only to have it mangle their thumbnails is a pretty bad user experience. This is a simple patch that just sets some flags in the GD functions if those flags are available.

09/12/07 18:32:21 changed by westi

  • keywords set to has-patch needs-testing.
  • severity changed from normal to major.

While I agree I would like to see this in 2.3.

It needs some testing before it can go in.

09/13/07 21:32:33 changed by ryan

  • priority changed from normal to high.

09/13/07 21:41:25 changed by Otto42

If anybody else wants to test, a bunch of transparent png's to test with can be found here: http://entropymine.com/jason/testbed/pngtrans/

12/09/07 11:38:21 changed by westi

  • owner changed from anonymous to westi.
  • status changed from reopened to new.

12/20/07 22:24:39 changed by westi

  • status changed from new to closed.
  • resolution set to fixed.

(In [6439]) Preserve PNG transparency/alpha during thumbnail creation. Fixes #2805 props Libertus/Otto42.