kerning problem in GD and php 5.3
Asked Answered
D

1

8

Knowing this problem has been adressed before at PHP update kerning problem with imagettftext() and imagefttext() functions but witout solution;

PHP5.3 seem to have kerning problems when printing text:

Look at the 'x' in the following examples (font: Ubuntu-M.ttf):

PHP5.2, ubuntu (good)

enter image description here

PHP5.3.2, ubuntu (worse, x is fattened)

enter image description here

PHP5.3.2, MAMP OSX (horrible)

enter image description here

Is there any solution to this?

Anyone with 5.3.6 installed care to try this?

regards, //t

Decipher answered 3/5, 2011 at 21:57 Comment(5)
This is probably not due to the PHP version, but the version of the bundled GD and freetype libraries. Do a phpinfo(), look up the version numbers and post them hereGemot
@Pekka: That really depends. PHP usually ships with it's own customised GD library but not always. Debian for example does not use the bundled versions but the global libgd.Greggrega
@Sander this should be not so much about GD as it's about Freetype (but probably, what you say applies there as well - it will sometimes be bundled, and sometimes not). Anyway, phpinfo() should always have the correct numbers, bundled or not, if I'm not mistakenGemot
Yes, true. phpinfo() knows best!Greggrega
yes, freetype version was the ause.Decipher
E
2

I attempted to replicate the middle image with my home machine after downloading the font (version 0.71.2 of Ubuntu font family). Arch Linux, x86_64, PHP 5.3.6, GD 2.0.34 (bundled), Suhosin patch, FreeType 2.4.4. I had better kerning on both e and x.

Image generation:

<?php
$img = imagecreatetruecolor(158, 72);
imagesavealpha($img, true);

$bg = imagecolorallocatealpha($img, 0, 0, 0, 127);
$black = imagecolorallocate($img, 0, 0, 0);
imagefill($img, 0, 0, $bg);

$text = "testar text"; // - was attempt at no aa, like example
imagettftext($img, 24, 0, 0, 36, -($black), 'Ubuntu-M', $text);
$text = "med text";
imagefttext($img, 24, 0, 12, 72, $black, 'Ubuntu-M', $text);

imagepng($img, 'test.png');
imagedestroy($img);
?>

Output:

output of attempt to duplicate second image in question

Ezequieleziechiele answered 18/6, 2011 at 6:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.