Andrew Gaffney <[EMAIL PROTECTED]> wrote:
: : 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
You haven't set the palette. You need to Allocate() colors into the palette before you can choose the Closest() color in the palette. I changed $blue to $green. It was easier to see the text that way.
I have reworked my script using another example I found and it works correctly for the most part, now.
#!/usr/bin/perl
use GD;
$im = new GD::Image(51,20);
$white = $im->colorAllocate(255,255,255); $black = $im->colorAllocate(0,0,0); $gray = $im->colorAllocate(132,132,132); $blue = $im->colorAllocate(206,206,255); $leftblue = $im->colorAllocate(231,231,255); $bottomblue = $im->colorAllocate(165,165,206); $rightblue = $im->colorAllocate(123,123,156); $topblue = $im->colorAllocate(214,214,255);
$im->transparent($white); $im->interlaced('true'); $im->filledRectangle(0,0,50,19,$white); $im->filledRectangle(3,3,50,19,$gray); $im->filledRectangle(0,0,47,16,$blue); $im->rectangle(0,0,47,16,$white); $im->line(1,0,46,0,$topblue); $im->line(47,1,47,15,$rightblue); $im->line(1,16,46,16,$bottomblue); $im->line(0,1,0,15,$leftblue); $im->string(gdSmallFont, 2, 2, "Contact", $black);
open IMAGE, "> /home/httpd/htdocs/testbutton.png"; binmode IMAGE; print IMAGE $im->png; close IMAGE;
The resulting image is <http://www.skylineaero.com/testbutton.png>. I was modeling the image after one I had previously done using Paint Shop Pro at <http://www.skylineaero.com/contactusbutton.gif>. They look pretty darn similar except for the text. Can anyone recommend a way to make the generated text (testbutton.png) look like the text in the hand-made one (contactusbutton.gif)? Also, since this will be a script to auto-generate these images with user-defined text, how can I center the text in the image (or even in the blue rectangle)? Should I use a different module for generating the text, or even for generating the whole image?
-- 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>