GD - way to preserve PNG transparency?

K

Kirk Is

So I'm trying to load a PNG with transprency...

use GD;
$im = GD::Image->newFromPng("orig/abe.png");
print $im->transparent(),"\n";

but it always prints -1
I think, confusing the issue, there might be two "blacks" in the palette,
one use in the image, and one to set the transperency...

The ancient version of PSP I'm using doesn't respect the transparency
either, but irfanview and browsers get it correct.

Any suggestions? Is there another way of loading the image that might
preserve the palette and the transparency better?

Thanks!
 
K

Kirk Is

Also, let me know if this is the correct newsgroup...
I know technically this is a module inssue, not core Perl, but the modules
group seems to be kind of dead. I don't know if there's a graphics
specific group that might know better?

I guess one thing is, maybe I could have done a better job exporting w/
GIMP? In terms of selecting a new unsed color, and doing a background
layer of that color, and then just picking that color specifically and
setting it transparent in GD.

But that would mean I'd have to redo 65 or so images, and I'd like to
avoid that if someone has a better idea...

Thanks!
 
B

Bill Ricker N1VUX

Kirk said:
So I'm trying to load a PNG with transprency... %<snip
but it always prints -1

Interesting. I haven't tried that, but I ought to play with transparency.

What verion of Perl GD:: modules are you using?

What version of the underlying GD libraries are you using?
(bgd.dll or libgd.so&.lib or whatever; libpng.lib also)

Where does the PNG with transparency come from? Which kinds of pallete and
transparency does it have? There are a large number of possibilities. If you
repeat the problem with one of the published test images, that might help.
(see below)

Boutell reports that as of gd 2.0.26, an issue with Binary Transparency was
fixed.
http://www.boutell.com/gd/
I think, confusing the issue, there might be two "blacks" in the palette,
one use in the image, and one to set the transperency...

That could be a problem, haven't tried that. Having the same RGB in the
palette of the input image twice could indeed be an error. Where did the
image come from?

Besides checking for uptodate libraries, I'd suggest getting some test images
designed for transparency and see how they work.
http://images.google.com/images?q=transparency png
http://entropymine.com/jason/testbed/pngtrans/


Cheers,

Bill
use.perl.org/~n1vux
 
K

Kirk Is

Interesting. I haven't tried that, but I ought to play with transparency.
What verion of Perl GD:: modules are you using?

2.30 I believe...that's the one that comes up with
ppm install http://theoryx5.uwinnipeg.ca/ppms/GD.ppd
which ActiveState recommends...
What version of the underlying GD libraries are you using?
(bgd.dll or libgd.so&.lib or whatever; libpng.lib also)

I'm not sure where to look for that...
Where does the PNG with transparency come from? Which kinds of pallete and
transparency does it have? There are a large number of possibilities. If you
repeat the problem with one of the published test images, that might help.
(see below)
http://kisrael.com/journal.aux/plumber.png


That could be a problem, haven't tried that. Having the same RGB in the
palette of the input image twice could indeed be an error. Where did the
image come from?

I generated that from the "Marios. 64." thing that was floating around, in
Gimp, by loading a .PSD, making only the one layer visible, then
saving/exporting. There are 64-odd images, so I probably shoulda just set
the background to something ugly and unused and then let GD recreate the
transparency, I wouldn't mind saving myself the work of doing it again
though.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top