Currently, image.inc when resizing a 8-bit PNG generates a 24-bit PNG.

Though 24-bit PNG display fine in all browsers when there is no alpha information, they use more bandwidth than 8-bit. This patch makes image.inc generate 8-bit PNG when given 8-bit PNG on resizing operations. The resizing is still done using 24-bit temporary image, indexing to 8-bit and polishing with imageColorMatch :

[IN:Original 8-bit image] => [Scaled 24-bit image] => [8-bit image] => [imageColorMatch] => [OUT:8 bit-image]

Included is a imageColorMatch replacement (translated from the C code) for those PHP installations that don't provide it. It's pretty slow, but as resizing is typically a 1-shot deal, I see no real problem there.

The conversion will _not_ work properly with transparent PNGs. Automating this would not give great results anyway because of the alpha thresholding.

This patch is against image.inc v1.12; v1.12+this_patch should work on at least Drupal 4.6 and 4.7

CommentFileSizeAuthor
image.inc.8bitpng.patch3.07 KBptaff

Comments

Tobias Maier’s picture

we dont accept new features against any already released version, only against the current developer version which is called CVS/HEAD
So please make a patch if necessary against CVS/HEAD - the upcomming drupal 4.7

ptaff’s picture

Version: 4.6.5 » x.y.z

The patch is already against the CVS' latest image.inc (v1.12) (which works with 4.6 and 4.7). Sorry, a simple case of mis-categorization.

robin monks’s picture

Category: feature » bug
Status: Needs review » Reviewed & tested by the community

Switched to bug report since this is really something we should do right, but don't.

Tested locally and all looked/worked well. I'd still like someone with intimate graphics+php knowledge to take a second look at this, but it should be good to go. Tested on WAMP/PHP5/MySQL5/Drupal CVS.

Robin
I ♥ Bugz

dries’s picture

Not sure this is a real bug, or whether it needs fixing ...

Stefan Nagtegaal’s picture

Assigned: ptaff » Stefan Nagtegaal
Status: Reviewed & tested by the community » Needs review

I'll investigate this...

drumm’s picture

Status: Needs review » Needs work

Fix up the code style.
- Two space indents only.
- Properly spaced and formatted /* */ comments above functions for auto-generated documentation
- Only // comments inline.

ricabrantes’s picture

Version: x.y.z » 7.x-dev

This is active??

robin monks’s picture

Oh yeah.

Robin
I ♥ Bugz

miopa’s picture

I would say it's a bug. My png thumbnails are often twice the size of the original image. Is it possible to port this solution to verzion 6?

Status: Needs work » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.