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


-- 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