On Sun, 21 Dec 2003, Andrew Gaffney wrote:
I think I've fixed this, too. It looks like it was some weird caching issue with Apache and mod_perl. I renamed the script and it works correctly every time now. Thank you for the suggestion to use stringTTF() or stringFT() to generate the text. I was able to use the array returned by it to center the text in the middle of the generated image. Thanks.
would you care to share your complete code? i just want it for some benchmarking to compare it with other ways to output random text nifty to a image :)
#!/usr/bin/perl
use GD; use CGI; use Image::Magick;
my $im = new GD::Image(61,20); my $cgi = new CGI; my $text = $cgi->param('text');
$white = $im->colorAllocate(255,255,255); $black = $im->colorAllocate(0,0,0); $gray = $im->colorAllocate(132,132,132); $blue = $im->colorAllocate(206,206,255); # Different shades of blue are to give it a slightly more 3D effect $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,60,19,$white); # Transparent background $im->filledRectangle(3,3,60,19,$gray); # Draw gray "shadow" rectangle $im->filledRectangle(0,0,57,16,$blue); # Draw blue foreground rectangle $im->rectangle(0,0,57,16,$white); # Make blue rectangle border transparent $im->line(1,0,56,0,$topblue); $im->line(57,1,57,15,$rightblue); $im->line(1,16,56,16,$bottomblue); $im->line(0,1,0,15,$leftblue); # Determine size of generated text in order to center it on the blue rectangle my @bounds = GD::Image->stringFT($black,"/share/skyline-src/arialnb.ttf",9,0,0,0,$text); $im->stringFT($black,"/share/skyline-src/arialnb.ttf",9,0,((57-$bounds[2])/2),13,$text);
# Write image to temporary PNG file
open IMAGE, "> /tmp/genbutton.png";
binmode IMAGE;
print IMAGE $im->png;
close IMAGE;
# Convert image to GIF file
my $image = new Image::Magick;
$image->Read('/tmp/genbutton.png');
srand;
my $filernd = int(rand 999);
my $file = "/home/httpd/htdocs/genbutton-${filernd}.gif";
$image->Write($file);
print $cgi->header;
print <<EOF;
<html>
<body>
<h3>A button has been generated with the text "${text}". It has been saved to the file "${file}". It is also shown below.</h3>
<p>
<img src='/genbutton-${filernd}.gif'>
</body>
</html>
EOF
-- 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>