How do you use Annotate in PerlMagick? a 10-line script

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
tdan

How do you use Annotate in PerlMagick? a 10-line script

Post by tdan »

This script produces a 1pixel blank image:

Code: Select all

#!/usr/bin/perl
use Image::Magick;
use strict;

my $image = new Image::Magick;
$image->ReadImage( 'xc:none' );
$image->Set( size => '500x500' );
$image->Annotate( text=>'This is a cool line of text', font=>'arial.ttf', fill=>'blue', pointsize=>'12', geometry=>'+0+14' );
$image->Write( '__TextOut.png' )
I put arial.ttf in the same directory as the script.

Any thoughts?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: How do you use Annotate in PerlMagick? a 10-line script

Post by magick »

Set the image size *before* you call ReadImage().
tdan

Re: How do you use Annotate in PerlMagick? a 10-line script

Post by tdan »

Ah yes - that did it.
tdan

Re: How do you use Annotate in PerlMagick? a 10-line script

Post by tdan »

OK, the text is printing but the following parameters don't do anything for me:
stretch - tried Condensed, UltraCondensed, Expanded...
style - tried Italic and Oblique
weight - tried different integers

I tried this with the Times font also.
Here's a sample script:

Code: Select all

#!/usr/bin/perl
use Image::Magick;
use strict;

my $image = new Image::Magick;
$image->Set( size => '500x500' );
$image->ReadImage( 'xc:none' );
$image->Annotate( text=>'This is a cool line of text\nHCB rocks\nLook 3 lines!', font=>'arial.ttf', fill=>'blue', pointsize=>'36', gravity=>'North', stretch=>10, style=>'Oblique', weight=>10 );
$image->Trim();
$image->Write( '__TextOut.png' )
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: How do you use Annotate in PerlMagick? a 10-line script

Post by magick »

Stretch, style, and weight are used to identify a font from the ImageMagick font list. However, you specified a particular font (arial.ttf) so no search is made.
Ximer

Re: How do you use Annotate in PerlMagick? a 10-line script

Post by Ximer »

And... how simulate oblique/italic font style?

I need this with font specified... example.. arial in italic...

thanks.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How do you use Annotate in PerlMagick? a 10-line script

Post by anthony »

You use a italic TTF file AlialItalic.ttf for example. Alrial has a whole family of font files.

however for oblique (or slanted) you can also use the annotate angle options. to angle the y axis by a few degrees.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply