How can I get the same annotation text effect as GD-lib?

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
hightman

How can I get the same annotation text effect as GD-lib?

Post by hightman »

Hello, this problem had puzzled me much long time.

When I annotate some small text (equal to or samller than 12px) on the picture, it looks very ugly and seems break up when I trun off the antialias effect.

Let's look following three pictures(I drew these pictures use PHP MagickWand extension & PHP-Gd2 extension)

1. Drew use ImageMagick-6.5.3-6 without antialias: Image
2. Drew use ImageMagick-6.5.3-6 with antialias: Image
3. Drew use PHP-GD2 (the text looks very clear): Image

How can I deal with this problem? I think this is not a FONT problem, maybe it can be fixed by modifing code on magick/annotate.c, but I cann't resolved it...
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How can I get the same annotation text effect as GD-lib?

Post by fmw42 »

hightman wrote:Hello, this problem had puzzled me much long time.

When I annotate some small text (equal to or samller than 12px) on the picture, it looks very ugly and seems break up when I trun off the antialias effect.

Let's look following three pictures(I drew these pictures use PHP MagickWand extension & PHP-Gd2 extension)

1. Drew use ImageMagick-6.5.3-6 without antialias: Image
2. Drew use ImageMagick-6.5.3-6 with antialias: Image
3. Drew use PHP-GD2 (the text looks very clear): Image

How can I deal with this problem? I think this is not a FONT problem, maybe it can be fixed by modifing code on magick/annotate.c, but I cann't resolved it...

Post your exact IM commands!

What IM method: label:, caption:, -annotate or -draw? see http://www.imagemagick.org/Usage/text/

Also do you know that GD is using the exact same font set (not just font name) as IM?
hightman

Re: How can I get the same annotation text effect as GD-lib?

Post by hightman »

I generate the two images use these Command, used the same font file for GD.

Code: Select all

convert  -size 60x20 xc:lightblue -font simsun.ttc  -pointsize 12 -fill black +antialias -annotate +3+15 "试试看" test1.jpg
convert  -size 60x20 xc:lightblue -font simsun.ttc  -pointsize 12 -fill black -antialias -annotate +3+15 "试试看" test2.jpg
The TTC Font file can be downloaded from here: http://www.czxiu.com/~hightman/simsun.tar.bz2(about 5.3MB)

The text annotated on the image was break-up, It seems these error was fixed in GD-lib along with a special algorithm.

gd used in PHP, php script run at the same machine ImageMagick installed, they are using same FreeType-2.3.7

Code: Select all

<?php
$im = imagecreate(60, 20);
$bg = ImageColorAllocate($im, 255, 255, 255);
$fg = imagecolorallocate($im, 0, 0, 0);

ImageFill($im, 0, 0, $bg);
ImageFTText($im, 9, 0, 3, 15, $fg, "simsun.ttc", "试试看");

header("Content-Type: image/jpeg");
ImagePng($im);
?>
hightman

Re: How can I get the same annotation text effect as GD-lib?

Post by hightman »

The problem code maybe here, (magick/annotate.c), but I dont know how to fix or adjust them... :(

...
1291 fill_opacity=(MagickRealType) (*p)/255.0;
1292 if (draw_info->text_antialias == MagickFalse)
1293 fill_opacity=fill_opacity > 0.5 ? 1.0 : 0.0;

1294 if (active == MagickFalse)
1295 q=GetCacheViewAuthenticPixels(image_view,x_offset,y_offset,1,1,
1296 exception);
...
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How can I get the same annotation text effect as GD-lib?

Post by fmw42 »

what version of IM are you using? If it is old, then upgrade and see if it works.


also see notes about unicode (utf-8) at http://www.imagemagick.org/Usage/text/#unicode

also add -strokewidth 1 to your command with and without +antialias

not sure if +antialias works with -annotate?
hightman

Re: How can I get the same annotation text effect as GD-lib?

Post by hightman »

fmw42 wrote:what version of IM are you using? If it is old, then upgrade and see if it works.


also see notes about unicode (utf-8) at http://www.imagemagick.org/Usage/text/#unicode

also add -strokewidth 1 to your command with and without +antialias

not sure if +antialias works with -annotate?
The version of my IM is the newest (6.5.3-6) ...
All your advice I had tried, but there wasn't any effects, because this is a clearType problem??
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How can I get the same annotation text effect as GD-lib?

Post by anthony »

This thread was transferred to developers forum (not by me).
viewtopic.php?f=2&t=13988
Interested parties to continue discussion there.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply