zentara wrote:
On Tue, 23 Dec 2003 07:44:59 -0500, [EMAIL PROTECTED] (Zentara)
wrote:

On Mon, 22 Dec 2003 09:42:31 -0600, [EMAIL PROTECTED] (Andrew
Gaffney) wrote:


Christian Bolstad wrote:

# 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);

I havn't tried it personnally yet, but I think you should be able to avoid writing that temporary png file. If you are using perl5.8 you could write to a variable, and then just have Image::Magick read from that. The following should show you the basic idea.

Well, here is a working method for perl5.8


#!/usr/bin/perl
use warnings;
use strict;
use GD;
use Image::Magick;

my $im = new GD::Image(61,20);
my $text = 'foobar!';

my $white = $im->colorAllocate(255,255,255);
my $black = $im->colorAllocate(0,0,0);
my $gray = $im->colorAllocate(132,132,132);
my $blue = $im->colorAllocate(206,206,255);
# Different shades of blue are to give it a slightly more 3D effect
my $leftblue = $im->colorAllocate(231,231,255);
my $bottomblue = $im->colorAllocate(165,165,206);
my $rightblue = $im->colorAllocate(123,123,156);
my $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,"./arial.ttf",9,0,0,0,$text);
#print "@bounds\n";
#$im->stringFT($black,"./arial.ttf",9,0,((57-$bounds[2])/2),13,$text);
$im->string(gdSmallFont, 2, 2, $text, $black);

# Write image to temporary PNG file
my $tmp = '';
open IMAGE, "+>",\$tmp or die $!;
binmode IMAGE;
print IMAGE $im->png;
close IMAGE;
# Convert image to GIF file
my $image = Image::Magick->new(magick=>'PNG');
$image->Read("\$tmp") or warn $!;
$image->Write(filename=>"$0.gif", compression=>'None');
__END__

Thanks. I'll try that.


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