Increase font quality at small sizes ?

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
ttmt
Posts: 4
Joined: 2011-10-26T06:33:50-07:00
Authentication code: 8675308

Increase font quality at small sizes ?

Post by ttmt »

Hi all

I'm using this simple script to create images of text in a set font and at a set size.

Code: Select all

<?php

  header('Content-Type: image/png');

  $text = 'Testing HHAVAHH';

  $output_image = new Imagick();
  $output_image->newImage(600, 200, '#dddddd');
  $output_image->setImageFormat("png");

  $text_draw = new ImagickDraw();
  $text_draw->setFont("corbelb.ttf");
  $text_draw->setFontSize(20);
  $text_draw->setFillColor("black");
  $output_image->annotateImage($text_draw, 10, 100, 0, $text);
  
  echo $output_image;
?>
Everything works as I expected but the quality of the type at small sizes isn't very good.

Is there anyway I can increase the quality of the images?

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

Re: Increase font quality at small sizes ?

Post by magick »

Make sure you have Freetype support built into ImageMagick. Type
  • convert -list format
and make sure the TTF coder has a mode of r--. If so you could always supersample. Render at a 40 pointsize then resize the image by 50%.
ttmt
Posts: 4
Joined: 2011-10-26T06:33:50-07:00
Authentication code: 8675308

Re: Increase font quality at small sizes ?

Post by ttmt »

If I type 'convert -list format' I get a long list with

TTF* TTF r-- TrueType font (Freetype 2.4.7)

so I assume I have FreeType support

How would I supersample, render at a 40 point size then resize the image by 50%

Regards

ttmt
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Increase font quality at small sizes ?

Post by anthony »

ttmt wrote:Everything works as I expected but the quality of the type at small sizes isn't very good.
What do you regard as 'small'.

Recentally I needed to generate text as very small pointsizes (for a Gnome Text File Thumbnail Generator) and as such did some research into finding TTF fonts that would work (and be legible) at very small sizes.

These were my results...

Code: Select all

# Small font selection -- you can download TTF's from network
# To install into ImageMagick, see:  http://www.imagemagick.org/Usage/#font
#
#font=Arial           pointsize=6    # 6,9 good  7,8 not so good 10,12 ideal
#font=ArialN          pointsize=7    #
#font=CourierNew      pointsize=6    # very light, needs auto-level
#font=CourierNewB     pointsize=6    # Best fixed width font at most sizes!
 font=PC              pointsize=7    # thinner but light, needs auto-level
#font=Terminal        pointsize=6    # 6 good  8 nice (more line spacing)
#font=PixelMix        pointsize=5    # 5 works 6 bad 7 overflows lines
#font=ETBT6001        pointsize=6    # very clear monospaced (6pt ideal)
#font=CoolThreePixels pointsize=4    # a little too small (5pt ideal)
#font=7px4bus         pointsize=7    # yuck 'a' (7pt ideal)
#font=Crystal         pointsize=6    # very near proportional (not quite)
#font=Verdana         pointsize=7    #\
#font=LucidaConsole   pointsize=6    # > proportional fonts (clean when small)
Note I was more interested in a mono-spaced font, However I found that both Arial and NewCourier generally worked well at all point sizes.

The PC font is only slightly more legible than NewCourier, (and slightly smaller even at larger pointsize)
The actual font filename is... PCCharSet.ttf

Note that if you use IM to read a TTF file as a image it will generate a sample page of the font.
for example...

Code: Select all

  convert Arial.ttf font_arial.png
I have a modified version of the TTF coder that includes more pointsizes in the 'waterfall' font list, including those at smaller point sizes so I can evaluate the font at small scales. I submitted it for IMv7 but have a INv6 version too. I also modified the 'phrase' to be a "Pangram", that is a string containing all the letters of the English alphabet.

Here is the modified TTF font sample page... the above produced.
Image

From this you can see that Arial at pointsize 4 or 5 is not really too small to be readable, though 6 does work well! similarly pointsizes 7 and 8 are not so good though remain readable. After that the font is rendered very well.

NOTE I found many fonts only work well at either the default pointsize, or a specialised one it was designed for.
The standard fonts seem to have the widest usage range, at small scales, but then, they have been worked on extensively just for that purpose. I hate to say it but... well done Microsoft! :mrgreen:

Your mileage may vary with your machine and text rendering delegate library.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
veranyon
Posts: 5
Joined: 2011-11-07T07:31:24-07:00
Authentication code: 8675308

Re: Increase font quality at small sizes ?

Post by veranyon »

2 anthony

echo -e "That which does not destroy me, only makes me stronger." | convert -font /usr/share/fonts/dejavu/DejaVuSans.ttf -pointsize 18 -trim +repage text:- text.png
Image

convert /usr/share/fonts/dejavu/DejaVuSans.ttf text.png
Image

Is there a difference? :)
pointsize 18
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Increase font quality at small sizes ?

Post by anthony »

veranyon wrote:2 anthony

echo -e "That which does not destroy me, only makes me stronger." | convert -font /usr/share/fonts/dejavu/DejaVuSans.ttf -pointsize 18 -trim +repage text:- text.png
Image

convert /usr/share/fonts/dejavu/DejaVuSans.ttf text.png
Image

Is there a difference? :)
pointsize 18
Your images are missing. probably restricted you just yourself! Try some other cloud file service, like a DropBox Public Folder.

Also I don't quite understand the question about difference. But as a guess...

The second bit of code will have produced the current IM 'font test page'. The new one I designed for IMv7 is similar, but uses a panogram (all letters of alphabet). The 'stronger' phrase is not a panogram. The new font test page also displays more point sizes around 12 point (and smaller) which are more commonly used by users.

I find the extremely small pointsizes (eg: 6 point) especially useful in seeing how well a font was designed.
Image
For example DejaVuSans (se above) likes to leave extra gaps between letters in the middle of words. (See above 'five' at 6pt and wizards at 5pt). This behaviour is disconcerting for use in things like text file preview and icon images.

The Arial font does not do this!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply