Font size not correct while annotating - magick++

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
writetonsharma
Posts: 6
Joined: 2013-05-28T04:34:59-07:00
Authentication code: 6789

Font size not correct while annotating - magick++

Post by writetonsharma »

I am using imagemagick 6.7.3 on windows XP compiled with Visual Studio 6.0.
I have the below code to annotate some text and I see that the font size is not set correctly. I doubt that a default font size is picked.

Code: Select all

Image image( Geometry(713,8), Color("#ffffff"));
image.fillColor("#000000");
image.density( Geometry(96, 96));
image.font("@.\Arial.ttf");
image.fontPointsize(5);
image.annotate("A long text here", WestGravity);
image.rotate(270);
image.write("test.png");
Other surprising thing I see is, if I change some sequence of the code, the font size changes to something else. Like if I set the font point size in the end.

Code: Select all

Image image( Geometry(713,8), Color("#ffffff"));
image.fillColor("#000000");
image.density( Geometry(96, 96));
image.font("@.\Arial.ttf");
image.annotate("A long text here", WestGravity);
image.rotate(270);
image.fontPointsize(5);
image.write("test.png");

I am not an expert but I think something is wrong. Depending on where I put set the font size, the font either become too large or too small.


Thanks,
Naveen.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Font size not correct while annotating - magick++

Post by magick »

Set the density to 72 then adjust your font pointsize.
writetonsharma
Posts: 6
Joined: 2013-05-28T04:34:59-07:00
Authentication code: 6789

Re: Font size not correct while annotating - magick++

Post by writetonsharma »

Thanks for looking at it.

I tried that -

Code: Select all

image.density( Geometry(72, 72));
But its still not working.

see the image. The top font is the correct one. Rest two below are either smaller or bigger.

https://docs.google.com/file/d/0B_-EiOs ... sp=sharing

Thanks.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Font size not correct while annotating - magick++

Post by magick »

You also need to set your font pointsize before you call image.annotate().
writetonsharma
Posts: 6
Joined: 2013-05-28T04:34:59-07:00
Authentication code: 6789

Re: Font size not correct while annotating - magick++

Post by writetonsharma »

yes, I did that only. So, its like the below code

Code: Select all

Image image( Geometry(713,8), Color("#ffffff"));
image.fillColor("#000000");
image.density( Geometry(72, 72));
image.font("@.\Arial.ttf");
image.fontPointsize(5);
image.annotate("A long text here", WestGravity);
image.rotate(270);
image.write("test.png");
Did I do correctly ?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Font size not correct while annotating - magick++

Post by magick »

Change "@.\Arial.ttf" to "@Arial.ttf". We're using ImageMagick 6.8.5-8, the latest release and it appears to render the font correctly.
writetonsharma
Posts: 6
Joined: 2013-05-28T04:34:59-07:00
Authentication code: 6789

Re: Font size not correct while annotating - magick++

Post by writetonsharma »

I tried this but the output is still the same. The font is bigger than 5point.

I can try the latest release but I was avoiding it. We use various non-windows platforms and it will take some time to compile the library on all these platforms with our new release due soon.

Do you think I can do something else in 6.7.3 to make it work ?
Post Reply