This code will take a quoted line of text as first commandline argument. It will then make an image of the text, crop it to size, mirror it, and combine it all into 1 file.
#!/usr/bin/perl use warnings; use strict; use Imager; my $text = shift || 'Perlmonks Rule'; #make the xsize huge to accept alot of text #it will be cropped to text size later my $img = Imager->new(xsize=>900,ysize=>50,channels=>4); my $blue = Imager::Color->new("#0000FF"); my $font = Imager::Font->new( file => 'Generic.ttf', #path to any font file color => $blue, size => 40); $img->string(font => $font, text => $text, x => 0, y => 40, size => 40, color => $blue, aa => 1); my ($neg_width, $global_descent, $pos_width, $global_ascent, $descent, $ascent) = $font->bounding_box(string => "$text"); print "$neg_width, $global_descent, $pos_width, $global_ascent,$descen +t, $ascent\n"; my $img1 = $img->crop(left=>$neg_width, right=>$pos_width, top=> -$global_descent, bottom=>$global_ascent + + 5); #fudge factor $img1->write(file=>$0.'.png', type=>'png') or die "Cannot write: ",$img1->errstr; my $img_mirror = $img1->copy(); $img_mirror->flip( dir => "h" ); $img_mirror->write(file=>$0.'-mirror.png', type=>'png') or die "Cannot write: ",$img_mirror->errstr; #make a unified image my $img_uni = Imager->new(xsize=>$pos_width * 2,ysize=>$global_ascent +,channels=>4); $img_uni->paste(left=>$pos_width,top=>0,img=>$img1); $img_uni->paste(left=>0,top=>0,img=>$img_mirror); $img_uni->write(file=>$0.'-uni.png', type=>'png') or die "Cannot write: ",$img_uni->errstr;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Mirrored text with Imager
by chanio (Priest) on Jul 27, 2005 at 07:37 UTC | |
by zentara (Cardinal) on Jul 27, 2005 at 12:10 UTC | |
by chanio (Priest) on Jul 27, 2005 at 17:19 UTC | |
by zentara (Cardinal) on Jul 28, 2005 at 15:30 UTC | |
by chanio (Priest) on Jul 30, 2005 at 16:17 UTC |