Edges of fonts appear distorted/less smooth

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?".
lmeurs
Posts: 9
Joined: 2008-11-05T04:33:00-07:00

Edges of fonts appear distorted/less smooth

Post by lmeurs »

LS,

We have written a Javascript/CGI-script that replaces text in HTML elements with an anti-aliased background image. The scripts work fine but for one thing: on some servers edges of letters happen to appear a bit distorted/less smooth. A fine example is the letter 'o':

Image

We are working with three servers:

- Windows XP SP3 development server with IM 6.2.8,
- Fedora 6 production server with IM 6.2.8,
- Suse 10.2 production server with IM 6.3.0.

One and the same script is running on all three of the servers, but unfortunately with two different kinds of results: the Fedora server produces the right result, the other two not, even though the Windows machine has the very same version of IM installed and Suse even has a newer version!

Can anyone tell us what we can do about it? Any help is appreciated!

Sincerely,

Laurens Meurs (Rotterdam, the Netherlands)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Edges of fonts appear distorted/less smooth

Post by fmw42 »

lmeurs wrote:LS,

We have written a Javascript/CGI-script that replaces text in HTML elements with an anti-aliased background image. The scripts work fine but for one thing: on some servers edges of letters happen to appear a bit distorted/less smooth. A fine example is the letter 'o':

Image

We are working with three servers:

- Windows XP SP3 development server with IM 6.2.8,
- Fedora 6 production server with IM 6.2.8,
- Suse 10.2 production server with IM 6.3.0.

One and the same script is running on all three of the servers, but unfortunately with two different kinds of results: the Fedora server produces the right result, the other two not, even though the Windows machine has the very same version of IM installed and Suse even has a newer version!

Can anyone tell us what we can do about it? Any help is appreciated!

Sincerely,

Laurens Meurs (Rotterdam, the Netherlands)

I am no expert on these matters, but I suspect the font you are using is not identical on each computer. Even if the name is the same, the source of the font may be different and this can cause slight differences in rendering. Also one font set may not have the exact size you have specified and it then needs to scale that from a smaller or larger one. So I would look into making sure you install the same font (say from the server that looks good) to the other servers.

When Anthony gets online later today, he can probably give you a clearer explanation.
lmeurs
Posts: 9
Joined: 2008-11-05T04:33:00-07:00

Re: Edges of fonts appear distorted/less smooth

Post by lmeurs »

Thanks for the reply, but I'm afraid it seems it has nothing to do with it since the same fonts are used on all three machines. IM reads the fonts from a local folder and not from a library of some sort...
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Edges of fonts appear distorted/less smooth

Post by magick »

Its possible you may have different Freetype versions on your machines or Freetype may be configured for the patented Apple hinting method on one server but not the next.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Edges of fonts appear distorted/less smooth

Post by anthony »

fmw42 wrote:I am no expert on these matters, but I suspect the font you are using is not identical on each computer. Even if the name is the same, the source of the font may be different and this can cause slight differences in rendering. Also one font set may not have the exact size you have specified and it then needs to scale that from a smaller or larger one. So I would look into making sure you install the same font (say from the server that looks good) to the other servers.
Fred is exactly correct. What fonts are avialable is very system dependent, and even depends on the "type.xml" file configuration that is used, and if using ghostscript fonts, then whether the ghostscript fonts are installed or in the right place.

IM is build with fedora/redhat linux in mind, and SuSE linux may not store fonts in the same location, and thus the "type.xml" does not find a nice font.

You did not give a sample of your command line (or program) but it may be you have not specified a font to use, so IM will try to find a reasonable default from what is present. Though I am not certain how it makes that determination.

See the top level page of IM Examples Usage pages for some more information on creating a "type.xml" using fonts that are present on your computer.

The best idea for consistancy, is to find a simple TTF font (like an Arial font), and specify the font file directly on the command line. Or create your own personal "type.xml" for IM to use and store it in the configuration search path (under linux in ".magick" sub-directory of your home). See the resources page on the IM web site for details.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Edges of fonts appear distorted/less smooth

Post by anthony »

magick wrote:Its possible you may have different Freetype versions on your machines or Freetype may be configured for the patented Apple hinting method on one server but not the next.
That I did not know about. though I have see some small variation in the resulting rendering of a font from different versions of freetype. But I do not have experience with different OS's.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
lmeurs
Posts: 9
Joined: 2008-11-05T04:33:00-07:00

Re: Edges of fonts appear distorted/less smooth

Post by lmeurs »

Thanks for the help, Magick! I am not that familiar with Linux, so it all is an exploration journey to me. Sometimes a fun one... :-)

The server that did give the wanted output is based on Fedora 6 and has freetype.i386 and freetype.x86_64 installed, both version 2.2.1.17.fc6. The other Linux server has Suse 10, freetype.i586 1.3.1-1193 and freetype2.i586 2.2.1.20061027-11 installed.

According to the version numbers I assume freetype on Fedora and freetype2 on Suse are pretty (almost) the same. Can it be that IM on Suse is using freetype.i586 1.3.1-1193 instead of the newer version freetype2.i586 2.2.1.20061027-11?

I have been looking for the configuration files and have found them, but I'am out of time now and really have got to run. Tomorrow I will continue my journey! Thanks again for the effort!
lmeurs
Posts: 9
Joined: 2008-11-05T04:33:00-07:00

Re: Edges of fonts appear distorted/less smooth

Post by lmeurs »

Anthony, for this script written in Perl I am actually using PerlMagick and I address the font in the following manner:

Code: Select all

$image->[0]->Annotate(font=>'./fonts/GOTHIC.TTF' , text=>'test 1 2 3...');
The same font is used on all three machines...
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Edges of fonts appear distorted/less smooth

Post by fmw42 »

lmeurs wrote:Anthony, for this script written in Perl I am actually using PerlMagick and I address the font in the following manner:

Code: Select all

$image->[0]->Annotate(font=>'./fonts/GOTHIC.TTF' , text=>'test 1 2 3...');
The same font is used on all three machines...
Not to belabor my point, but just because the name of the font is GOTHIC.TTF, does not necessarily mean that all three versions are exactly the same. If you have obtained and/or installed all three from the same source then I beg your pardon. But if the freetype version is not the same and that is not the cause of your difficulties, then I would look to the font files. Anthony actually has some nice scripts, show_fonts, graphics_utf and text2img_fixed, that will build images from the the font sets. You can then create and examine the actual fonts from each computer and see if they show any differences. You can get the script from http://www.imagemagick.org/Usage/scripts/ . I found these scripts to be very useful. Anthony can give you more details and explain if they are freetype-dependent or not.

For example:

show_fonts -2 -o arial2.png Arial
Image

graphics_utf -n | text2img_fixed -font Arial -line 16 arial.png
Image
lmeurs
Posts: 9
Joined: 2008-11-05T04:33:00-07:00

Re: Edges of fonts appear distorted/less smooth

Post by lmeurs »

Sorry it took a while for me to answer, but when trying to remove and reinstall freetype (`yum inunstall freetype`) a lot of other things got removed as well! (probably it is obvious to you guys what I did wrong, but to me it still is foggy :-)). Since this server was just a few days old, no back-ups were made yet and a reinstallation seemed to be the only solution...

The server that did give the wanted output is based on Fedora 6 and has freetype.i386 and freetype.x86_64 installed, both version 2.2.1.17.fc6. How do I know which version is used: i386 or x86_64? The other Linux server has Suse 10, freetype.i586 1.3.1-1193 and freetype2.i586 2.2.1.20061027-11 installed.

According to the version numbers of freetype on Fedora and freetype2 on Suse, can I assume they are pretty much the same? I have looked up the IM configuration files on both machines and uploaded them to http://www.wishdesign.nl/fora/configure.fedora.xml and http://www.wishdesign.nl/fora/configure.suse.xml, maybe this clears something up?

I have tried to run show_fonts, but on both servers I got an error:

Code: Select all

> /bin/bash ./show_fonts -2 -o arial2.png Arial
'/show_fonts: line 38: syntax error near unexpected token `
'/show_fonts: line 38: `}
After removing a trailing space on line 38 I got the following error, which I do not know what to do with:

Code: Select all

> /bin/bash ./show_fonts -2 -o arial2.png Arial
'/show_fonts: line 54: syntax error near unexpected token `in
'/show_fonts: line 54: `  case "$1" in
And unfortunately graphics_utf gives similar errors...

I really do hope someone can help me out here, any help is still well appreciated! :-)
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Edges of fonts appear distorted/less smooth

Post by anthony »

lmeurs wrote:The server that did give the wanted output is based on Fedora 6 and has freetype.i386 and freetype.x86_64 installed, both version 2.2.1.17.fc6. How do I know which version is used: i386 or x86_64? The other Linux server has Suse 10, freetype.i586 1.3.1-1193 and freetype2.i586 2.2.1.20061027-11 installed.
I doubt you can install BOTH the i368 and the x86_64 packages simultaneously unless the package name is also different. However you can find out exactly what each package installs by looking at the file list.

Code: Select all

rpm -qil {package}
This gives the header information and the files for that package. I do this all the time.

As for what specific freetype IM is using, you will need to determine which library file is linked into IM. Run this to see the libraries being used

Code: Select all

ldd /usr/bin/convert
In my case I see
libfreetype.so.6 => /usr/lib/libfreetype.so.6
so I can then see what package provided that freetype

Code: Select all

rpm -qf /usr/lib/libfreetype.so.6
which for my fedora 8 system was freetype-2.3.5-4.fc8. SuSE also use the RPM system so you should have no problems doing this.

To fix you will need to configure and re-build IM. The ideal way would be to generate a SRPM package that uses freetype2, (you could download the SRPM from SuSE as a starting point) but re-configuring a sRPM is no so easy to describe. However the start point is modifying the "spec" file which contains the configuration command used as part of the build process. This take time, but the knowledge gained can be worth it.
I have tried to run show_fonts, but on both servers I got an error:

Code: Select all

> /bin/bash ./show_fonts -2 -o arial2.png Arial
'/show_fonts: line 38: syntax error near unexpected token `
'/show_fonts: line 38: `}
After removing a trailing space on line 38 I got the following error, which I do not know what to do with
Fixed. Looks like your BASH is very error-sensitive. Mine works fine. I have never seen a shell error on an extra space character before.

Code: Select all

> /bin/bash ./show_fonts -2 -o arial2.png Arial
'/show_fonts: line 54: syntax error near unexpected token `in
'/show_fonts: line 54: `  case "$1" in
And unfortunately graphics_utf gives similar errors...
Again I have never seen this. The program is designed to run on ANY Bourne type shell, not just BASH.

Try changing the "/bin/bash" on the very FIRST line to "/bin/sh"
and remove the -2 flag (the -2 has the only 'BASH' specific feature being used) I really need to figure out a better way!

Addendum: I have uploaded a updated version of show_fonts that does NOT use that BASH specific feature. It should appear in a few days. If the first line of the script is '#!/bin/sh' then you hvae found the new version.

Only the -3 'style' makes use of graphics_utf to generate a table of UTF characters. Also see IM Examples for other ways of using this script to examine a UFT compilent font and look for other 'special' symbols and characters
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
lmeurs
Posts: 9
Joined: 2008-11-05T04:33:00-07:00

Re: Edges of fonts appear distorted/less smooth

Post by lmeurs »

Dear Anthony,

First I'd like to thank you for your time and the effort you put into this issue! I looked up which versions of freetype we us, and I think it all looks alright.

Code: Select all

> ldd /usr/bin/convert
...
libfreetype.so.6 => /usr/lib/libfreetype.so.6
...
Then I queried freetype with RPM:

Code: Select all

> rpm -qf /usr/lib/libfreetype.so.6
freetype2-2.3.5-4.3
Unfortunately the results from show_fonts are no different after altering the first line and ommitting the -2 flag. Your upload has not appeared yet, I will wait for that!

According to you warning I have to say that rebuilding IM as sRPM is way out of my league, I'm afraid :-), maybe it is time to hire a professional...

The Fedora server (that does handle the fonts edges correctly) seems to have two kinds of IM and FreeType installed, one in the lib and the other in the lib64 folder, but convert uses the latter one.

Code: Select all

> rpm -q ImageMagick
ImageMagick-6.2.8.0-4.fc6
ImageMagick-6.2.8.0-4.fc6

> rpm -q freetype
freetype-2.2.1-17.fc6
freetype-2.2.1-17.fc6

> ldd /usr/bin/convert
...
libfreetype.so.6 => /usr/lib64/libfreetype.so.6
...
lmeurs
Posts: 9
Joined: 2008-11-05T04:33:00-07:00

Re: Edges of fonts appear distorted/less smooth

Post by lmeurs »

Ok, the new show_fonts was available for download and we tried it, but it still trips over the $1 variable:

Code: Select all

> sh ./show_fonts
'/show_fonts: line 60: syntax error near unexpected token `in
'/show_fonts: line 60: `  case "$1" in

> /bin/bash ./show_fonts -2 -o arial2.png Arial
'/show_fonts: line 60: syntax error near unexpected token `in
'/show_fonts: line 60: `  case "$1" in

> /bin/bash ./show_fonts -o arial2.png Arial
'/show_fonts: line 60: syntax error near unexpected token `in
'/show_fonts: line 60: `  case "$1" in

> /bin/sh ./show_fonts -o arial2.png Arial
'/show_fonts: line 60: syntax error near unexpected token `in
'/show_fonts: line 60: `  case "$1" in
Anyway we try to call the script (bash or sh, with or without -2), we do not get any further than line 60.

Then we thought it maybe had something to do with the fonts we used, so we uploaded a few fonts (TrueType and OpenType, exotic and less exotic), experimented with them (png/jpg, different sizes, anti-alias on/off) and saved the results in a png-file http://www.wishdesign.nl/fora/fonts1.png.

The first font is one I made myself 8 years ago and exists out of traced bitmaps: this explains the jagged edges (see close-up in the background). The strange thing is that the text created by IM on the Fedora server (the server that always returns the right output) has very rough edges compared to the results of Windows and Suse.

Do the results in the png-files mean anything to anyone? :-)

Then again, when I look at the config files http://www.wishdesign.nl/fora/configure.fedora.xml and http://www.wishdesign.nl/fora/configure.suse.xml, I see some big differences in the 'configure' variables. Can this have something to do with it?

I would like to try a few possible configurations (mix the two confic files a bit), but I do not know when the configuration files are loaded: at boot time or each time IM is called? If at boot time: how can I reload the config files without having to reboot the server?

Thanks again in advance for any help!!!
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Edges of fonts appear distorted/less smooth

Post by anthony »

lmeurs wrote:Ok, the new show_fonts was available for download and we tried it, but it still trips over the $1 variable:

Code: Select all

> sh ./show_fonts
'/show_fonts: line 60: syntax error near unexpected token `in
'/show_fonts: line 60: `  case "$1" in
Anyway we try to call the script (bash or sh, with or without -2), we do not get any further than line 60.
From all the manuals, and tests I have done on both Linux and Solaris, the above is correct!!! It is complaining on 'in' but in is the token that should be used.

The only thing I can think of is if you cut and pasted the script rather than directly saved it, in which case it may have been given a UTF representation rather than plain ASCII text. I have see this happen.

Bash or any Bourne shell deritive should not be objecting to that code!
Then again, when I look at the config files http://www.wishdesign.nl/fora/configure.fedora.xml and http://www.wishdesign.nl/fora/configure.suse.xml, I see some big differences in the 'configure' variables. Can this have something to do with it?
You will need to work out what those configuration options actually mean in terms of how FreeType performs.

If it is for installation locations, that should be left as is. Concentrate on any options to do with font handling and rendering.

freetype is not a daemon, that runs continuously, as such the config files will be read when the library is actually used, so changes should be seen immediately in any new program runs.

However it amy also be a compile time configuration option difference. SuSE builds there own completely independent set of RPM packaged binaries to that of Redhat and Fedora systems.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
lmeurs
Posts: 9
Joined: 2008-11-05T04:33:00-07:00

Re: Edges of fonts appear distorted/less smooth

Post by lmeurs »

Eventually we installed Fedora 7 instead of Suse 10.2 and everything works like a charm. Thanks again so much for your help!!!
Post Reply