Page 1 of 1
Can't draw text using Annotate
Posted: 2007-11-21T21:57:54-07:00
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?
Re: Can't draw text using Annotate
Posted: 2007-12-03T18:36:19-07:00
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.
Re: Can't draw text using Annotate
Posted: 2007-12-08T17:00:22-07:00
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.
Re: Can't draw text using Annotate
Posted: 2007-12-11T00:15:16-07:00
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
Re: Can't draw text using Annotate
Posted: 2007-12-11T14:44:56-07:00
by RetroJ
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);
Re: Can't draw text using Annotate
Posted: 2007-12-11T17:15:53-07:00
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?
Re: Can't draw text using Annotate
Posted: 2007-12-12T13:13:02-07:00
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!
Re: Can't draw text using Annotate
Posted: 2007-12-13T01:46:23-07:00
by csharppmf
To All: The web service provider fixed the problem. Thanks to all. Originator of post.