URGENT!! Corrupt 16x16 png icon file with GD!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
blueillusion
Forum Newbie
Posts: 2
Joined: Wed Oct 27, 2010 11:21 pm

URGENT!! Corrupt 16x16 png icon file with GD!

Post by blueillusion »

Hey,

Having a problem with GD loading a 16x16px image and outputting to the browser, yet with other images of the same size it works fine, it's also GD version related because offline on my test server it works fine, online no.

Online server GD version: bundled (2.0.34 compatible)

Offline test server GD version: 2.0 or higher

Here's some test code I'm using, literally opens the file and outputs to the browser:

Code: Select all

header('Content-Type: image/png');
$img = imagecreatefrompng('page_white.png');
imagepng($img);
Images:
Original icon file, not corruption
Original icon file, not corruption
original-icon.png (294 Bytes) Viewed 546 times
Corrupt icon outputted to the browser
Corrupt icon outputted to the browser
corrupt-icon.png (227 Bytes) Viewed 546 times

Please could someone help out with this, would be great.. going nuts over this problem!
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: URGENT!! Corrupt 16x16 png icon file with GD!

Post by pickle »

No idea why this is happening, but try opening up the PNG in Photoshop/Gimp and re-saving it. Maybe that'll flip whatever bit GD is chocking on.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
blueillusion
Forum Newbie
Posts: 2
Joined: Wed Oct 27, 2010 11:21 pm

Re: URGENT!! Corrupt 16x16 png icon file with GD!

Post by blueillusion »

pickle wrote:No idea why this is happening, but try opening up the PNG in Photoshop/Gimp and re-saving it. Maybe that'll flip whatever bit GD is chocking on.
Thanks Pickle! I'd already tried doing this ages ago; however, I opened up a good icon that works and the one that doesn't, noticed that the one that doesn't work is greyscale, and the other is RGB.. changing to RGB and saving allowed it to work online. It's strange that this is happening though!

:)
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: URGENT!! Corrupt 16x16 png icon file with GD!

Post by Weirdan »

That's a known issue with GD - it does not support grayscale images in its internal representation and converts them to indexed palette images:
gd2 manual wrote: If the PNG image being loaded is a truecolor image, the resulting gdImagePtr will refer to a truecolor image. If the PNG image being loaded is a palette or grayscale image, the resulting gdImagePtr will refer to a palette image.
Post Reply