Alright, the problem is as follows. I am trying to create an image via imagecreatetruecolor. Basicly I convert sprite files (sprites as in you see in those 2d sidescrolling beat-em up games) to gif. Even though everything is completely and fully working there is just one thing I just can't seem to fix.
Since those sprites use color palettes they have no transparency, yet the transparency is defined through the first index of the color palette.
Means the parser knows which parts of the image have to be transparent, when rendering.
Now the problem is that imagecolortransparent can only make COLORS transparent, but not specific index colors in the palette. So if there are multiple colors in the palette but with different indexes, the color, since they're the same are both transparent in the end.
So my question is: is it somehow possible to only make specific indexed colors transparent instead of a color itself?
Because if it doesn't I see no other option than to create a complete gif encoder just for this little feature. And I honestly dont want to do that >__>
I could also make it an alpha based image, but i'd like to keep the images filesize small in the end.
Thanks in advance!
imagecolortransparent: color, but not index dependant
Moderator: General Moderators
Re: imagecolortransparent: color, but not index dependant
As long as the sprites are palette images, you should be able to do exactly what you would first think:
If the sprites really have the first index as transparent (and not the index of the top-left pixel) then pass 0 to imagetransparent.
The reason being that GD, when it comes to palette images, deals with palette indexes - not colors. For example, if you do imagecolorat(X,Y) you'll get the color's index, not the RGB(A) integer.
If the sprites really have the first index as transparent (and not the index of the top-left pixel) then pass 0 to imagetransparent.
The reason being that GD, when it comes to palette images, deals with palette indexes - not colors. For example, if you do imagecolorat(X,Y) you'll get the color's index, not the RGB(A) integer.
Re: imagecolortransparent: color, but not index dependant
Thanks for the answer, but I still don't really understand what you mean...
So in order to make GD treat the image like a palette image I have to use the function imagetruecolortopalette() ?
But I still don't know how I would be able to pass a index number to the imagecolortransparent() function as it requires a color through the imagecolorallocate() function. And again to this function I can also only pass the color values but no indexes.
Heres a picture of the color palette that is being used. The first color with index 00 is white. However the last color with a different index (ff) is also white.
Now imagecolortransparent makes both transparent. And I still don't know how I can pass any sort of index color to any function.
I can set the whole palette with imagecolorset() but then again, there is no way I know of which lets me write index colors, means where I have to pass an index and not a color to.

I'm sorry if you answered it, but if so could you elaborate it a bit more? Thanks.
So in order to make GD treat the image like a palette image I have to use the function imagetruecolortopalette() ?
But I still don't know how I would be able to pass a index number to the imagecolortransparent() function as it requires a color through the imagecolorallocate() function. And again to this function I can also only pass the color values but no indexes.
Heres a picture of the color palette that is being used. The first color with index 00 is white. However the last color with a different index (ff) is also white.
Now imagecolortransparent makes both transparent. And I still don't know how I can pass any sort of index color to any function.
I can set the whole palette with imagecolorset() but then again, there is no way I know of which lets me write index colors, means where I have to pass an index and not a color to.

I'm sorry if you answered it, but if so could you elaborate it a bit more? Thanks.
Re: imagecolortransparent: color, but not index dependant
I am still in need of a solution to this problem. Note: I won't bump this anymore.