How can I get sharp text?

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
maozhua.net

How can I get sharp text?

Post by maozhua.net »

convert -background transparent -fill blue -pointsize 12 label:Hello,ImageMagick test.png
Text generated by this command is blurry, How can I get sharp text? Thanks.
maozhua.net

Re: How can I get sharp text?

Post by maozhua.net »

I found it, use +antialias to turn off antialias, but the image generated still looks ugly, what's the problem?
maozhua.net

Re: How can I get sharp text?

Post by maozhua.net »

It just can not produce normal look text?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How can I get sharp text?

Post by anthony »

Prehaps if you link in a copy of the example 'unsharp' text that you put somewhere on the web (try one of the photo sites if you don't have anywhere) then we can see what you mean by it being 'fuzzy'.

Note text is generally aliased. meaning the edge pixels are combined with the background to attempt to produce a smoother looking image. Without this you get a very pixelated 'staircase' type of edge to the text.

See IM examples, text
http://www.imagemagick.org/Usage/text/
for lots of examples of normal IM text output.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
maozhua.net

Re: How can I get sharp text?

Post by maozhua.net »

Image

Image

The first image was generated by command:
convert -background white -fill blue -font arial +antialias -pointsize 12 label:ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmlopqrstuvwxyz test.png

and the second one is what they actually look like,
you can notice the difference: B Q W X m r
maozhua.net

Re: How can I get sharp text?

Post by maozhua.net »

and my platform is windows2000, ImageMagick-6.2.9-Q8, thanks
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How can I get sharp text?

Post by anthony »

Can you give a thrid example of the default aliases text you claim is too 'fuzzy'.
It will neet to be more than a two color image!

We may be able to convert that to a bitmap in a more consistant way.

However you are right the anti-aliased form could probably be a lot better.

You best solution is probably to use a 'bitmap font' designed for the specific pointsize and density, rather than the more typical truetype, or vector font.
However I have not seen much use of bitmap fonts in IM for some time.

Can someone in the know enlighten us?
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
maozhua.net

Re: How can I get sharp text?

Post by maozhua.net »

Image

convert -size 380x29 xc:transparent -draw "fill tomato rectangle 0,0 190,28 fill limegreen rectangle 191,0 379,28 fill blue text 5,15 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmlopqrstuvwxyz'" test.png

It's not quite suitable for my application, I prefer the not-anti-aliased text as we usually see,
maybe 'bitmap font' is the best solution.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How can I get sharp text?

Post by anthony »

I tried a few thresholding techniques on that image, and did not get a good bitmap font result. The 'X' is especially bad in this regard.

Looks like we need a bitmap font at the right scale.

For example this is a 'snapshot' of the X windows bitmap font I am using on my Xterminal...
Image
However it is a X windows font. (in this case 8x15 )

Hmm online my IM was able to get that font directly using...

Code: Select all

 convert -font '-misc-fixed-medium-r-normal--15-145-75-75-c-80-iso10646-1' \
        label:'Some Text String abcXYZ'   bitmap_font.png
But that only works when my X windows server is running, so it is no good for windows or batch processing.

WARNING: IM Bug found! While the above returned the bitmaps font, IM did not set the 'baseline' of the font right, so all the letters sat on the bottom-most line of the image. Any decender was clipped. there was however pleanty of space for the font to be positioned correctly within a label.


We need to access bitmaps fonts like this batch wise.

Are you using windows, unix or a mac environment?
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
maozhua.net

Re: How can I get sharp text?

Post by maozhua.net »

Windows for development, and linux for production.
Actually, I come from China, and as I know, there are NO bitmap fonts for Chinese, so I think it will be a problem if IM can not produce identical not-anti-aliased text as we usually see for typical true type fonts or vector fonts.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How can I get sharp text?

Post by anthony »

That would be a problem, though I believe there are bitmaps chinese fonts too.
There are japanese and koren fonts..

development may have discontinued however, but I am sure they exist somewhere.
try searching the old X windows sources.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
maozhua.net

Re: How can I get sharp text?

Post by maozhua.net »

Sorry, it's my mistake, Chinese do have some bitmap fonts.
Thanks a lot :D
maozhua.net

Re: How can I get sharp text?

Post by maozhua.net »

more questions :)
Actually, the simsun.ttf font(delivered with windows) contains 3 bitmap fonts - 12px, 14px and 16px, so how can I specify IM to use these fonts instead of the vector font within it?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How can I get sharp text?

Post by anthony »

That is the question I would like cristy to answer.

however if you knwo the files you can try specifying the specific font file you want IM to use with -font

let us know how it goes.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
maozhua.net

Re: How can I get sharp text?

Post by maozhua.net »

Yes, I am calling IM using '-font /path/to/simsum.ttf', but I have no idea how to specify IM to use a particular bitmap font within this file :(
And I have tried to extract the bitmap fonts from the file using fontforge, but failed
Post Reply