Cannot for the life of me get annotate to do anything

PerlMagick is an object-oriented Perl interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning PerlMagick.
Post Reply
aporthog
Posts: 37
Joined: 2012-05-30T08:24:46-07:00
Authentication code: 13

Cannot for the life of me get annotate to do anything

Post by aporthog »

I've been working for two days to try to add some text to an image and nothing I try works.

I started on Solaris simply using 'convert' to try and do it. In most cases the image is created fine but never with any text. Here are some of the things I tried:

# convert L1522.tif -background White label:'Faerie Dragon' +swap -gravity Center -append crop.tif
# convert L1522.tif -gravity North -background White label:"Faerie Dragon" crop.tif
# convert L1522.tif -annotate +5+5 'Something' crop.tif
# convert L8320.tif -annotate 0 'something' -fill black crop.tif
# convert L7726.tif -draw 'rectangle 5,128,114,145' -font 'Times New Roman' -fill white -annotate +10+10 'this' crop.jpg
# convert L7726.tif -background lightblue -fill blue -font Arial -size 165x70 -pointsize 12 label:Anthony crop.gif
# convert crop.jpg -background Khaki label:'Faerie Dragon' +swap -gravity Center -append crop2.jpg

The closest to success I got was using '-draw'. I got a small black rectangle but no visible text inside.

Then I read there may be issues with the way ImageMagick was installed, some components needed for annotation might not have been included, so I switched to using Windows and still no luck. I installed Ghostscript first as was recommended. Then I installed PerlMagick and used the sample program below:

use strict vars;
use Image::Magick;

my $p = new Image::Magick;
$p->Read('L8728.tif');
#$p->Annotate(font=>'times.ttf', pointsize=>40, fill=>'green', text=>'Blah!');
$p->Annotate(font=>'c:\Windows\Fonts\times.ttf', pointsize=>40, fill=>'green', text=>'Blah!');
#$p->Label(font=>'times.ttf', pointsize=>40, fill=>'green', text=>'Blah!');
$p->Write ('crop.jpg');

In all cases trying different things I get a perfectly good jpeg out but any added text is never to be seen. The source tiffs are 2000px wide and 400px high. Help! I've looked at all the examples I could find online, tried everything in the official documentation. I don't get any error messages.

Right now I'm using ImageMagick-6.7.7-Q16 on 32-bit Windows XP.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Cannot for the life of me get annotate to do anything

Post by fmw42 »

# convert L1522.tif -background White label:'Faerie Dragon' +swap -gravity Center -append crop.tif
# convert L1522.tif -gravity North -background White label:"Faerie Dragon" crop.tif
# convert L1522.tif -annotate +5+5 'Something' crop.tif
# convert L8320.tif -annotate 0 'something' -fill black crop.tif
# convert L7726.tif -draw 'rectangle 5,128,114,145' -font 'Times New Roman' -fill white -annotate +10+10 'this' crop.jpg
# convert L7726.tif -background lightblue -fill blue -font Arial -size 165x70 -pointsize 12 label:Anthony crop.gif
# convert crop.jpg -background Khaki label:'Faerie Dragon' +swap -gravity Center -append crop2.jpg

Define all your settings after the input, then put -draw, -annotate, etc just before the output. Be sure to specify a fill color other than the background color so you can see your text. Be sure to specify a pointsize

Try this using the internal IM image, logo:

convert logo: -fill black -gravity center -font Arial -pointsize 48 -annotate -150+0 "sometext" logo_text.tif
aporthog
Posts: 37
Joined: 2012-05-30T08:24:46-07:00
Authentication code: 13

Re: Cannot for the life of me get annotate to do anything

Post by aporthog »

fmw42 wrote:
# convert L1522.tif -background White label:'Faerie Dragon' +swap -gravity Center -append crop.tif
# convert L1522.tif -gravity North -background White label:"Faerie Dragon" crop.tif
# convert L1522.tif -annotate +5+5 'Something' crop.tif
# convert L8320.tif -annotate 0 'something' -fill black crop.tif
# convert L7726.tif -draw 'rectangle 5,128,114,145' -font 'Times New Roman' -fill white -annotate +10+10 'this' crop.jpg
# convert L7726.tif -background lightblue -fill blue -font Arial -size 165x70 -pointsize 12 label:Anthony crop.gif
# convert crop.jpg -background Khaki label:'Faerie Dragon' +swap -gravity Center -append crop2.jpg

Define all your settings after the input, then put -draw, -annotate, etc just before the output. Be sure to specify a fill color other than the background color so you can see your text. Be sure to specify a pointsize

Try this using the internal IM image, logo:

convert logo: -fill black -gravity center -font Arial -pointsize 48 -annotate -150+0 "sometext" logo_text.tif
OK, this is encouraging. When I typed your example exactly I got the annotated logo. So my IM installation is working fine. When I replaced the 'logo' with my filename, same result as before. logo_text.tif is generated fine but no text:

convert L8728.tif -fill black -gravity center -font Arial -pointsize 48 -annotate -150+0 "sometext" logo_text.tif

Could it be printing somewhere off the screen? Perhaps I don't understand the offset notation. L8728 is 2200x220.

My image is mostly white with some black text, so I don't think it's there and I just can't see it.

My tiff image is here: http://www.megafileupload.com/en/file/3 ... 8-tif.html
Last edited by aporthog on 2012-05-30T10:01:42-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Cannot for the life of me get annotate to do anything

Post by fmw42 »

post a link to your tif file (or any example tif file that fails), so others can test.
aporthog
Posts: 37
Joined: 2012-05-30T08:24:46-07:00
Authentication code: 13

Re: Cannot for the life of me get annotate to do anything

Post by aporthog »

OK, what I think is happening is the tiff's palette is screwing things up. I increased the color depth to 16 million colors in IrfanView and saved it as a test file. Working on that test file I got annotate to work. It also works when converting the file to grayscale or bitonal first BTW.

Could it be IM is adding the text OK but since the text color doesn't correspond exactly to an entry in the palette it is simply not displaying? I think I'll poke around in a hex editor. Either that or IM simply doesn't cope well with paletted tiffs which admittedly aren't exactly common. I'll experiment with choosing a fill color that exactly corresponds with a palette entry just to see if that's what's happening. But for my task at hand hopefully I'll be able to increase the color depth on the convert command line first before the other operations and see if that works, though I don't know exactly how to do that just yet.
myicq
Posts: 29
Joined: 2012-04-11T04:23:21-07:00
Authentication code: 8675308

Re: Cannot for the life of me get annotate to do anything

Post by myicq »

This may be necro-posting, but I had exactly the same issue, and found what seemes to cause the situation.

This does not change the image:

Code: Select all

mogrify -pointsize 150 -fill yellow -gravity north -annotate  "%t" x.jpg
But this works as expected:

Code: Select all

mogrify -pointsize 150 -fill yellow -gravity north -annotate +0+0 "%t" x.jpg
For whatever reason, annotate without geometry does nothing.
48clyde
Posts: 1
Joined: 2016-10-20T12:35:17-07:00
Authentication code: 1151

Re: Cannot for the life of me get annotate to do anything

Post by 48clyde »

I had the same problem. It turned out the tiff image had a geometry offset of 1192x+2228 because I had extracted a smaller image from a large tiff.

$ identify Kepler-*
Kepler-1.tiff TIFF 3508x2480 3508x2480+1192+2228 8-bit sRGB 13.82MB 0.000u 0:00.000

I fixed this by adding a +repage to change the offset +0+0 before the annotate option.

$ identify Kepler-*
Kepler-1.tiff TIFF 3508x2480 3508x2480+0+0 8-bit sRGB 13.83MB 0.000u 0:00.000
Post Reply