QUOTED_MESSAGE: > I'm using Imager for creating special charts in > computational biology. For this purpose it's critical that > I have maximum control over size and positioning of single > characters. Thus, I tried to get the boundaries of the > visible character, which is a lot smaller than the > "sign" with all the surrounding white space, > through the bounding_box method. Now, the problem is that I > get a gap between the end of the visible character and the > predicted end x + (bbox[2]-bbox[0]), but only with _some_ > characters like 'G' or 'C', whereas 'X' or 'V' work > perfectly. I add some sample code below. Some results I got > can be seen under > > http://page.inf.fu-berlin.de/~schuster/logotest/ > > I'm using FreeType2 (libfreetype.6.3.2) with perl5.8.0, > font 'arial.ttf' from Win98. Imager version: > 0.41. > > I'd be so gratefull for any help, I need this stuff > done for my bachelor- thesis ;-) > > Tnx, Benjamin Schuster > > You need to add a font-directory through the $path > variable! output will be written to 'logotest.png' in the > current dir. #--------------------------- Code > ---------------------------- #!/usr/bin/perl > -w > use Imager qw(:handy); > > #Letter to draw > $key = 'G'; > > $xsize = 200; > $ysize = 200; > > #letter target-width/heigth $lw = 150; > $lh = 150; > > #Some font path > $path = '.'; > > my $normFont=NF(file=>"$path/arial.ttf") > or die "Couldn't create font: $Imager::ERRSTR\n"; > > #Create some colors > my $white = NC('#FFFFFF'); my $black = > NC('#000000'); > my $red = NC('#FF0000'); > my $green = NC('#00FF00'); my $blue = > NC('#0000FF'); > > #create picture > my $i=Imager->new(xsize=>$xsize, > ysize=>$ysize); $i->box(filled=>1,color=>$white); > > #get the size of the character to draw my @bbox = > $normFont->bounding_box(string=>$key, size=>$lh, > sizew=>$lw); > > #Draw a black box determining target-width > $i->box(color=>$black, > xmin=> > 25, > xmax=> > 25+$lw, > ymin=> > 25, > ymax=> > 25+$lh, > filled > => 0); > > #Print the character > $i->string(font=>$normFont, > string=>$key, > x=>25, > y=>25+$lh, > size=>$lh, > sizew=>$lw, > color=>NC('#FF00FF'), > aa=>1); > > #Draw a blue box showing the predicted span of the > visible character $i->box(color => > $blue, > xmin > => 25 + $bbox[0], > xmax > => 25 + ($bbox[2]-$bbox[0]), > ymin > => 25 + $lh - $bbox[5], > ymax > => 25 + $lh - $bbox[4]); > > $i->write(file=>'logotest.png'); #--------------------------- > End ----------------------------- > > > ------------------------------------------------- This > mail sent through IMP: http://horde.org/imp/
EKKI skrifa neitt hér:
© 2000-2002 Bjarni R. Einarsson / fyrirspurnir / skilmálar / þakkir /