WordPress.org

Make WordPress Core

Opened 8 years ago

Closed 3 years ago

Last modified 3 months ago

#2805 closed defect (bug) (fixed)

Preserve PNG transparency/alpha during thumbnail creation

Reported by: Libertus Owned by: westi
Milestone: 2.5 Priority: high
Severity: major Version: 3.0.4
Component: Administration Keywords:
Focuses: Cc:

Description

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

Attachments (4)

wp_create_thumbnail-preserve-PNG-transparency.diff (1.2 KB) - added by Libertus 8 years ago.
the patch
wp_create_thumbnail-preserve-PNG-transparency-ideal.diff (1.3 KB) - added by Libertus 8 years ago.
same patch but with function return value changed
2805.diff (757 bytes) - added by Otto42 7 years ago.
Simpler patch
test_pngs_8-32_bit.zip (18.7 KB) - added by bfred.it 3 years ago.
It contains 2 PNG files exported from Fireworks at 8bit and 32bit

Download all attachments as: .zip

Change History (17)

comment:1 Libertus8 years ago

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

Libertus8 years ago

same patch but with function return value changed

comment:2 Nazgul7 years ago

  • Resolution set to wontfix
  • Status changed from new to closed

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

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

comment:3 jberthon7 years ago

  • Resolution wontfix deleted
  • Status changed from closed to reopened

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

comment:4 foolswisdom7 years ago

  • Milestone set to 2.4 (future)

Otto427 years ago

Simpler patch

comment:5 Otto427 years ago

  • 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.

comment:6 westi7 years ago

  • Keywords has-patch needs-testing added
  • 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.

comment:7 ryan7 years ago

  • Priority changed from normal to high

comment:8 Otto427 years ago

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/

comment:9 westi6 years ago

  • Owner changed from anonymous to westi
  • Status changed from reopened to new

comment:10 westi6 years ago

  • Resolution set to fixed
  • Status changed from new to closed

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

bfred.it3 years ago

It contains 2 PNG files exported from Fireworks at 8bit and 32bit

comment:11 in reply to: ↑ description bfred.it3 years ago

  • Keywords has-patch needs-testing removed
  • Resolution fixed deleted
  • Status changed from closed to reopened
  • Version changed from 2.1 to 3.0.4

The solution doesn't work for 8 bit PNGs. I attached the two files I encountered the problem with, in a ZIP.

comment:12 Otto423 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

That's actually a problem with the GD library and also that 8-bit PNGs are palletized. No programmatic solution can create transparent 8-bit PNG files properly.

Use 24-bit PNGs if you want transparency to be preserved.

comment:13 harimaliya3 months ago

That's problem with GD library.fixed with more then 8-bit PNGs.

Note: See TracTickets for help on using tickets.