Andrew Gaffney wrote:

> zentara wrote:
> > On Sat, 20 Dec 2003 14:23:15 -0600, [EMAIL PROTECTED] (Andrew
> > Gaffney) wrote:
> >
> >
> >>I want to write a Perl program that will auto generate GIF images. The images that 
> >>I want
> >>to generate will be about 30x80. It will be a black rectangle starting in the 
> >>bottom-right
> >>with a few pixels border on the top and left. There will be a light blue rectangle
> >>starting in the top-left with a few pixels border on the bottom and right. There 
> >>will then
> >>be 6- or 8-point black bold centered text that will be specified when the program 
> >>is run.
> >>The background also need to be transparent. Can anyone give me any pointers on 
> >>writing a
> >>Perl program that can do what I need? Links to examples are good too. Thanks.
> >
> >
> > Well, gifs were shunned by alot of the software writers because of
> > the old patent issues. So your best bet will be to make your image as
> > a jpg or png, then convert it to gif afterwards.
> >
> > If you want to make an animated gif, you can
> > use something like this:
> > system("gifsicle -lforever $graphical*.gif > $graphical.anim.gif")
> >
> > Here is a simple script using GD.
>
> <snip>
>
> I wrote my own script based off your example and the docs at
> <http://search.cpan.org/~lds/GD-2.11/GD.pm>. When I run the below program, I get:
>
> skyline skyline-src # ./genbutton.pl
> gd-png:  fatal libpng error: Invalid number of colors in palette
> gd-png error: setjmp returns error condition
>
> Here is my code:
>
> #!/usr/bin/perl
>
> use warnings;
> use GD;
>
> $im = new GD::Image->new(51, 20);
>
> $gray  = $im->colorClosest(127, 127, 127);
> $blue = $im->colorClosest(0, 0, 127);
> $white = $im->colorClosest(255, 255, 255);
> $black = $im->colorClosest(0, 0, 0);
> $im->transparent($white);
>
> $im->filledRectangle(0, 0, 51, 20, $white); # Transparent background fill
>
> $im->filledRectangle(4, 4, 51, 20, $gray);
> $im->filledRectangle(0, 0, 47, 16, $blue);
> $im->string(gdSmallFont, 3, 3, "Test", $black);
>
> open(PNG,"> /home/httpd/htdocs/testbutton.png") or die "Can't write GDtest.png: 
> &!\en";
> binmode (PNG);
> print PNG $im->png;
> close(PNG);
>
> --
> Andrew Gaffney

You must have 2 ** bit-per-pixel colors for the palette.  You need not use them all, 
but they
need to be defined, or it throws the coding process off.  Fill the blanks with white, 
or use:

00  R:  000   G:  000   B:  000
01  R:  128   G:  000   B:  000
02  R:  000   G:  128   B:  000
03  R:  128   G:  128   B:  000
04  R:  000   G:  000   B:  128
05  R:  128   G:  000   B:  128
06  R:  000   G:  128   B:  128
07  R:  192   G:  192   B:  192
08  R:  128   G:  128   B:  128
09  R:  255   G:  000   B:  000
10  R:  000   G:  255   B:  000
11  R:  255   G:  255   B:  000
12  R:  000   G:  000   B:  255
13  R:  255   G:  000   B:  255
14  R:  000   G:  255   B:  255
15  R:  255   G:  255   B:  255

To give yourself a nice broad-spectrum selection of colors.  The compression aogorithm 
is based
around string table inidices, which must start at the right place.

Joseph


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to