GD transparent index shifting

GD and GD2 are useful libraries for creating graphics on-the-fly. Discuss your PHP GD and GD2 scripts here.

Moderators: onion2k, General Moderators

Post Reply
yum-jelly
Forum Commoner
Posts: 98
Joined: Sat Oct 29, 2005 9:16 pm

GD transparent index shifting

Post by yum-jelly »

I am working on adding ellipse cropping tool for my SGML capture system, but I am having some trouble with the transparent index color shifting position in the palette. When I first set the transparent color it always is in index 1, but after calling imagecopy() to layer the ellipse cropping area it get shifted in the palette. I figured allocating (1) color would make it shift to index (2), but it gets shifted to a random index and then set the transparent color to the orignal transparent color but to some index that is not in the palette anymore. Confused, so am I!

Say you have a image with 200 colors in a palette of 256 colors. The 200 colors are the only colors used. So before layering the transparent index is at index (1), after layering index (1) still holds the transparent color, but the transparent index has moved to index (222), which is not in the range of the active color palette.

So does anyone know how one can multi layer images, while not shifting the transparent index everytime you allocate a new color? I can do this fine with ImageMagick, but I am trying to keep development to just PHP, so users will not have to install other things just to support different shaping tools!

Here is example of the cropping tool so you can see what I trying to do...

http://www.ya-right.com/tools.php?t=0&s ... 632cfe5524

TIA

yj!
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Moved to PHP-GD.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

As far as I know there's no way to control the exact palette position of any particular color unless you rewrite the palette by hand or copy it from another image.
Pierre.gd
Forum Newbie
Posts: 5
Joined: Wed Mar 15, 2006 9:23 am

Post by Pierre.gd »

Can you provide a small script to reproduce what you want to do? The elliptical selection does not really matter. Also be sure to use the bundled gd as Jcart noticed.
Post Reply