On Wed, 3 Dec 2008 12:45:15 -0500
[EMAIL PROTECTED] wrote:
| On Tue, 02 Dec 2008 18:08:18 +0100
| Benoit VARVENNE <[EMAIL PROTECTED]> wrote:
|
| >Hello,
| >
| >I'm a quite new Image Magick user and I wish to locate ending position of a
| >text on the image (text annotated through "Annotate" method).
| > $image->Annotate(
| > x => $X,
| > y => $Y,
| > font => 'arial.ttf',
| > pointsize => $fontSize,
| > undercolor => "white",
| > skewX => 0,
| > skewY => 0,
| > fill => 'black',
| > text => $myText
| > );
| >What I wish to obtain is something like :
| > It's beginning position ($X) + length_of_text*fontSize
| > == ending pixel on the image ???
| >The above formula does not work and I'm not really used to such text
| >manipulation.
| >
| >Can someone help me ?
| >
| >Thanks a lot
| >Beno__t
|
| Here is an example, the secret is to give the same options to QueryFontMetrics
| as you do in the Annotate. Please disregard the gravity suggestion is my
other response...
| the correct term in IM is align. Gravity positions the origin on the page.
| See QueryMultilineFontMetrics() for multiline text; and always check the
return
| array values from it, to make sure what they are. They may change from IM
version,
| or the docs may be obsolete.
|
| This example will split a sentence into words an automatically position the
words.
|
| #################################################3
| #!/usr/bin/perl
| use warnings;
| use strict;
| use Image::Magick;
|
| my $image = Image::Magick->new;
| $image->Set(size=>'500x600');
| my $rc = $image->Read("xc:white");
|
| my $str = 'Just Another Perl Hacker';
| my (@words) = split ' ',$str;
| #print join "\n",@words,"\n";
|
| my ($x,$y) = (100,100);
|
| foreach my $word (@words){
|
| $image->Annotate(
| pointsize => 24,
| fill => '#000000ff', #last 2 digits transparency in hex ff=max
| text => $word,
| gravity => 'NorthWest',
| align => 'left',
| x => $x,
| y => $y,
| );
|
| my ( $character_width,$character_height,$ascender,$descender,$text_width,
| $text_height,$maximum_horizontal_advance, $boundsx1, $boundsy1,
| $boundsx2, $boundsy2,$originx,$originy) =
| $image->QueryFontMetrics(
| pointsize => 24,
| text => $word,
| gravity => 'NorthWest',
| align => 'left',
| x => $x,
| y => $y,
| );
|
| print "( $character_width, $character_height,
| $ascender,$descender,
| $text_width, $text_height,
| $maximum_horizontal_advance,
| $boundsx1, $boundsy1,
| $boundsx2, $boundsy2,
| $originx,$originy)\n";
|
| $x = $x + $originx + $character_width/3; # add a space
| print "_________________________________$x\n";
|
| }
|
| $image->Write("$0.png");
|
| exit;
| __END__
|
| zentara
|
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]>
-----------------------------------------------------------------------------
"Oh, the pain... the pain of it all!" -- Doctor Smith, Lost in Space
-----------------------------------------------------------------------------
Anthony's Home is his Castle http://www.cit.gu.edu.au/~anthony/
_______________________________________________
Magick-users mailing list
[email protected]
http://studio.imagemagick.org/mailman/listinfo/magick-users