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?
Can't draw text using Annotate
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Can't draw text using Annotate
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.
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/
https://imagemagick.org/Usage/
Re: Can't draw text using Annotate
I found that I have to give Annotate a gravity setting like gravity=>'north'. try that.csharppmf wrote:The instruction:
$image->Annotate(font=>'Helvetica', pointsize=>12, text=>$text, x=>10, y=>30);
fails to draw text on a image.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Can't draw text using Annotate
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
See Text Positioning with Gravity
http://imagemagick.org/Usage/annotating/#text_gravity
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: Can't draw text using Annotate
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);
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Can't draw text using Annotate
Converting that to command line...
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?
Code: Select all
convert -size 320x200 xc:lightgray -font Courier -pointsize 32 -fill black -gravity north -annotate +0+0 'Hello, World!' x:
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/
https://imagemagick.org/Usage/
Re: Can't draw text using Annotate
Ah yes, that was it. Thanks.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!
As per ghostscript fonts, I used your image_type_gen script. Thanks for that too!
Re: Can't draw text using Annotate
To All: The web service provider fixed the problem. Thanks to all. Originator of post.