php - Letter 'j' bugged with imagettftext function -


i've created script generate avatar using php , work fine when there letter j in $data1['username'], letter erase part of previous letter. note : use calibri bold italic (downloaded here) code :

$image = imagecreatefrompng("avatar.png");     $couleur = imagecolorallocate($image, 0, 0, 0);     $largeur_source = imagesx($image);      $fontfile = 'calibri.ttf';     $angle = 0;     $police = 18;     $text_size = imagettfbbox($police, $angle, $fontfile, 'hub de '.$data2['nom']);      $text_size2 = imagettfbbox($police, $angle, $fontfile, $data1['username']);      $text_width = (($text_size[2] + $text_size[4]) / 2) - (($text_size[0] + $text_size[6]) / 2);     $text_width2 = (($text_size2[2] + $text_size2[4]) / 2) - (($text_size2[0] + $text_size2[6]) / 2);     $x = ($largeur_source - $text_width)/2;     $x2 = (176 - $text_width2)/2 + 74;     //imagestring($image, $police, $x, $y, $texte_a_ecrire, $couleur);     imagettftext($image, $police, $angle, $x2, 175, $couleur, $fontfile, $data1['username']);     imagettftext($image, $police, $angle, $x, 35, $couleur, $fontfile, 'hub de '.$data2['nom']);     imagepng($image);  

when $data1['username'] = 'paj46 string looks : script's return

looks font has no kerning pairs table

look here kerning

  • you have calculate on integers dont use x/2 direct round up .. ceil()
  • if have width of image in $largeur_source use !
  • use result[2] or result[4] imagettfbbox() calculate. (values same)

<?php     $image = imagecreatefrompng("avatar.png");     $couleur = imagecolorallocate($image, 0, 0, 0);     $largeur_source = imagesx($image);      $fontfile = '59250___.ttf';     $angle = 0;     $police = 24;     $text_size = imagettfbbox($police, $angle, $fontfile, 'hub de' );      $text_size2 = imagettfbbox($police, $angle, $fontfile, 'username');      $x  = ceil(($largeur_source - $text_size[2])  / 2);     $x2 = ceil(($largeur_source - $text_size2[2]) / 2);     imagettftext($image, $police, $angle, $x2, 80, $couleur, $fontfile, 'username');     imagettftext($image, $police, $angle, $x, 35, $couleur, $fontfile, 'hub de ');     imagepng($image);  

enter image description here


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -