Re: [GD-DEVEL] Newbie transparent gif question
[email protected] (Roger Oberholtzer) Fri, 02 May 2008 08:44:09 +0200
| Newsgroups | php.gd.devel |
|---|---|
| Message-ID | <[email protected]> |
On Wed, 2008-04-30 at 16:24 +0200, Pierre Joye wrote: > Hi Roger, > > On Mon, Apr 28, 2008 at 9:59 AM, Roger Oberholtzer <[email protected]> wrote: > > > > I am trying to create transparent gifs via gd 2.0.32 on openSUSE Linux. > > Nothing fancy. I set the entire image to the transparent color, and then > > draw on top. I only see the color I defined, not a transparent image. My > > viewer does support transparent gifs. I test viewed one just to be sure > > (konqueror in kde 3). Transparent gifs have the transparent part shown > > as a checker board. > > > > Code snippet: > > > > gdImagePtr imBase = gdImageCreate(100,100); > > int grey = gdImageColorAllocate(imBase, 200, 200, 200); > > By the way, with palette image, the first allocated color will be the > background/transparent color. > > > gdImageColorTransparent(imBase, grey); > > This line is not required (but does not hurt). > > > gdImageFilledRectangle(imBase, 0, 0, 100,100, grey); > > That neither. The image is zeroed when you create it. Zero being the > first color in your palette, you already have a grey filled image. But > this color is the transparent/background color. > > > Then I draw some lines or things on top in colors other than grey. Then > > I save the image. But the grey is shown as, well, grey. Not > > transparent. > > > > What obvious thing have I missed? > > > Can you show me the full code please? I tried allocating the color I want to be transparent first, but it had no effect. I also tried not filling the plot with grey, but that also had no effect. The code is rather large. So I have provided the effective GD part. The a, b, c, etc. bits are where I had some location references that would just get in the way: // Init a plot gdImagePtr imBase = gdImageCreate(470, 1000); gdFontPtr font = gdFontGetLarge(); int grey = gdImageColorAllocate(imBase, 200, 200, 200); int black = gdImageColorAllocate(imBase, 0, 0, 0); int orange = gdImageColorAllocate(imBase, 255, 165, 0); int yellow = gdImageColorAllocate(imBase, 255, 255, 0); gdImageColorTransparent(imBase, grey); gdImageFilledRectangle(imBase, 0, 0, 470, 1000, grey): gdImageSetThickness(imBase, 1); // Draw some lines, rectangles, polygons or text using calls like: gdImageFilledRectangle(imBase, a, b, c, yellow); gdImageLine(imBase, a, b, c, d, black); gdImageString(imBase, font, a, b, (unsigned char *) bLabel, black); gdImageFilledPolygon(imBase, points, pinfo->number_of_points, black); gdImagePolygon(imBase, points, pinfo->number_of_points, red); // Save the plot FILE *out = fopen(current, "wb"); gdImageGif(imBase, out); fclose(out); gdImageDestroy(imBase); That is pretty much it. Nothing odd. If I remove calls to gdImageFilledRectangle, gdImageString, gdImageFilledPolygon and gdImagePolygon, it makes no difference. -- Roger Oberholtzer OPQ Systems / Ramböll RST Ramböll Sverige AB Kapellgränd 7 P.O. Box 4205 SE-102 65 Stockholm, Sweden Office: Int +46 8-615 60 20 Mobile: Int +46 70-815 1696