On Thu, 4 Dec 2008 09:39:34 +1000 Anthony Thyssen <[EMAIL PROTECTED]> wrote:
>Very useful script for experimentation... > >I have saved the above script in IM examples, scripts area, with >minor modifications to make it more verbose. > http://www.imagemagick.org/Usage/scripts/annotate_words.pl > >>From the output I notice that the caret moves forward by 'originx' >but that originx is really only the integer ceiling of 'text_width' > >1/ have you tried to draw from a non-integer starting point and > did it work? That is can words (or characters within the words) > be drawn at non-integer increments. The fonts are after all defined > in terms of vectors with lots of internal floating point curve > positions. > >2/ Have you tried the above with a highly non-standard font like > "lokicola" and many symbol fonts ? That is a font that regularly > overflows the bounds they themselves define for the characters > drawing area. Can you figure out the text's real drawing area? > > The test is to draw the bounds in a colored rectangle, then draw the > text over the top of this to see how well they match up. > > > Anthony Thyssen ( System Programmer ) <[EMAIL PROTECTED]> Here is a more general purpose script for experimentation. I did notice that rotations, and mixing different font families can give inconsistent results. It seems that rotations and skewing can be tricky to deal with, probably some trigonometric calculations are needed to avoid collisions. But is you stick with a constant font, it works pretty well, as long as you don't rotate. #!/usr/bin/perl use warnings; use strict; use Image::Magick; my $image = Image::Magick->new; $image->Set(size=>'800x400'); my $rc = $image->Read("xc:white"); my $str = 'Just Another Perl Hacker and not another c slacker'; my (@words) = split ' ',$str; #print join "\n",@words,"\n"; #shuffled options my @styles = map {$_->[0]} sort { $a->[1] <=> $b->[1]} map {[$_, rand(1)]} qw(Normal Italic Oblique Any); my @stretch = map {$_->[0]} sort { $a->[1] <=> $b->[1]} map {[$_, rand(1)]} qw(Normal UltraCondensed ExtraCondensed Condensed SemiCondensed SemiExpanded Expanded ExtraExpanded UltraExpanded); # on linux from xlsfonts #my @fonts = qw(-mozilla-arial-bold-r-normal--30-180-100-100-p-153-iso8859-1 # -mozilla-courier-medium-i-normal--24-180-100-100-m-113-iso8859-1 # -adobe-courier-bold-o-normal--11-80-100-100-m-60-iso8859-1 # ); my @fonts = qw( -mozilla-arial-*-*-*--*-180-100-100-p-153-iso8859-1 -mozilla-courier-*-*-*--*-180-100-100-m-113-iso8859-1 -mozilla-helvetica-*-*-*--*-150-100-100-p-131-iso8859-1 # -adobe-courier-*-*-*--*-80-100-100-m-60-iso8859-1 # -adobe-utopia-*-*-*--*-140-75-75-p-79-iso8859-14 #-adobe-times-*-*-*--*-240-75-75-p-124-iso8859-2 ); my @fill = qw(black green red blue purple); my @points = map {$_->[0]} sort { $a->[1] <=> $b->[1]} map {[$_, rand(1)]} qw(12 14 16 18 20 22 24 26 28 30); # starting point my $x = 50; my $y = 50; my $toggle = -1; # make up a random layout of words foreach my $word (@words){ push (@styles,shift(@styles)); #circular lists push (@stretch,shift(@stretch)); push (@fill,shift(@fill)); push (@points,shift(@points)); push (@fonts,shift(@fonts)); $toggle *= -1; my $pointsize = $points[0]; my $scale = (1 + int rand 3).','.(1 + int rand 3); my $rotata = 0; #$toggle * int rand 45; my $skewx = $toggle * (1 + int rand 15); my $skewy = $toggle * (1 + int rand 15); my $fill = $fill[0]; my $font = $fonts[0]; my %options =( align => 'left', antialias => 1, pointsize => $pointsize, fill => $fill, # scale => $scale, text => $word, gravity => 'NorthWest', x => $x, y => $y, skewx => $skewx, skewy => $skewy, rotate => $rotata, font => $font, ); my ( $character_width,$character_height,$ascender,$descender,$text_width, $text_height,$maximum_horizontal_advance, $boundsx1, $boundsy1, $boundsx2, $boundsy2,$originx,$originy) = $image->QueryFontMetrics( %options ); print "__________ $word starts at ___________$x\n"; print "( char_width->$character_width, char_height->$character_height, ascender->$ascender, descender->$descender, width ->$text_width, text_height->$text_height, max_horizontal_advance->$maximum_horizontal_advance, boundsx1->$boundsx1, boundsy1->$boundsy1, boundsx2->$boundsx2, boundsy2->$boundsy2, originx->$originx, originy->$originy )\n"; $image->Annotate( %options ); $x = $x + $text_width + $character_width/3; # add a space } $image->Write("$0.png"); exit; __END__ zentara -- I'm not really a human, but I play one on earth. http://zentara.net/Remember_How_Lucky_You_Are.html _______________________________________________ Magick-users mailing list [email protected] http://studio.imagemagick.org/mailman/listinfo/magick-users
