Can't draw text using Annotate

PerlMagick is an object-oriented Perl interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning PerlMagick.
Post Reply
csharppmf

Can't draw text using Annotate

Post by csharppmf »

The instruction:

$image->Annotate(font=>'Helvetica', pointsize=>12, text=>$text, x=>10, y=>30);

fails to draw text on a image. An instruction such as

$image->Draw(primitive=>"line", points=>"0,150 0,50");

works, fine.

My web service provider insists it is a "coding" problem and wants $75/hr
to have a programmer review the code. I think it is a font installation problem
with there linux server. We are stuck on this, what can I do?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Can't draw text using Annotate

Post by anthony »

I would first go back to basics. What fonts is available, and try to generate a simple label image. Make sure you can see any errors being produced.

The problem is usally one of environment, such as 'gs' or ghostscript not found, or the TTF font file not found, etc etc etc. Start as simple as you can and build.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
RetroJ
Posts: 108
Joined: 2006-10-25T08:12:50-07:00

Re: Can't draw text using Annotate

Post by RetroJ »

csharppmf wrote:The instruction:

$image->Annotate(font=>'Helvetica', pointsize=>12, text=>$text, x=>10, y=>30);

fails to draw text on a image.
I found that I have to give Annotate a gravity setting like gravity=>'north'. try that.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Can't draw text using Annotate

Post by anthony »

Gravity is only a specification of what the offset means. That is all.

See Text Positioning with Gravity
http://imagemagick.org/Usage/annotating/#text_gravity
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
RetroJ
Posts: 108
Joined: 2006-10-25T08:12:50-07:00

Re: Can't draw text using Annotate

Post by RetroJ »

anthony wrote:Gravity is only a specification of what the offset means. That is all.

See Text Positioning with Gravity
http://imagemagick.org/Usage/annotating/#text_gravity

Perhaps I am observing a bug then. In the following program, if I remove the gravity from the Annotate, no text is drawn.

Code: Select all

#! /usr/bin/perl

use strict;
use warnings;
use Image::Magick;

my $image = Image::Magick->new(size=>'320x200');
$image->Read ('xc:lightgray');
$image->Annotate (text=>"Hello, World!",
                  font=>"Courier",
                  pointsize=>32,
                  fill=>'black',
                  gravity=>'north');
$image->Write ("x:");
undef ($image);
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Can't draw text using Annotate

Post by anthony »

Converting that to command line...

Code: Select all

convert -size 320x200 xc:lightgray -font Courier -pointsize 32 -fill black -gravity north -annotate +0+0 'Hello, World!' x:
I see text just fine in the right place!

Trying the perl... Yeap that comes out perfectly fine too.

NOTE: without a gravity, or some other appropriate offset the text is drawn. but with the 'baseline start point' at 0,0. Which mean only the bottom of the comma will probably be visible!!!!!! Try adding a +20+20 offset if you what to turn off gravity! The link I gave previously explains this quite throughly!

Note "Courier" font is a ghostscript font! Is you ghostscript working with IM correctly?
Is this font listed in "convert -list type" or "convert -list font" (what ever is appropriate for your IM version. If the file pointed to by the system "type.xml" file correct (it may be an an indirect font link from "type-ghostscript.xml". Have you ever even seen 'Courier' in you current IM installation?
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
RetroJ
Posts: 108
Joined: 2006-10-25T08:12:50-07:00

Re: Can't draw text using Annotate

Post by RetroJ »

anthony wrote: NOTE: without a gravity, or some other appropriate offset the text is drawn. but with the 'baseline start point' at 0,0. Which mean only the bottom of the comma will probably be visible!!!!!! Try adding a +20+20 offset if you what to turn off gravity!
Ah yes, that was it. Thanks.

As per ghostscript fonts, I used your image_type_gen script. Thanks for that too!
csharppmf

Re: Can't draw text using Annotate

Post by csharppmf »

To All: The web service provider fixed the problem. Thanks to all. Originator of post.
Post Reply