zentara wrote:
On Tue, 23 Dec 2003 09:22:01 -0500, zentara <[EMAIL PROTECTED]>
wrote:


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;


Well, just I went back and tested this again. F#$%king Image::Magick
dosn't work with this method. Somehow I got it to work before
posting, but it was a fluke. I think I must have accidently
created a $tmp file, and IM was using it. Image::Magick dosn't like reading from a tmp scalar.


But good news....Imager does.
So in case anyone was banging their head on the wall
wondering why it didn't work, here is a better method
using Imager. Plus Imager makes a smaller gif. :-)

#!/usr/bin/perl
use warnings;
use strict;
use GD;
use Imager;

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;
#print $tmp;

# Convert image to GIF file
my $img = Imager->new;
$img->read(data=>$tmp, type=>'png')
           or die "Cannot read: ", $img->errstr;

$img->write(file=>"$0.gif", type=>'gif')
           or die "Cannot write: ",$img->errstr;

__END__

I'd never tried your last post, but I will try this one, especially since it actually works ;) Thanks.


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