Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

kerning problem in GD and php 5.3

Tags:

php

gd

kerning

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

like image 231
Teson Avatar asked May 03 '11 21:05

Teson


1 Answers

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

like image 110
Iiridayn Avatar answered Sep 18 '22 19:09

Iiridayn