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

Community
  • 1
  • 1
Teson
  • 6,644
  • 8
  • 46
  • 69
  • 2
    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 here – Pekka May 03 '11 at 22:00
  • @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. – Sander Marechal May 04 '11 at 09:17
  • 1
    @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 mistaken – Pekka May 04 '11 at 09:19
  • Yes, true. `phpinfo()` knows best! – Sander Marechal May 04 '11 at 09:29
  • 1
    yes, freetype version was the ause. – Teson Dec 05 '11 at 16:26

1 Answers1

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

Iiridayn
  • 1,747
  • 21
  • 43