|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-11-16 20:55 UTC] stanislav at ww9 dot ru
Description: ------------ Just wanted to write a text on an image with tranperent image and got strange result. Writing text on an image using some true type fonts like this one http://ww9.ru/zeferinotwo.ttf causes letters to overlap each other like here http://ww9.ru/test.php Reproduce code: --------------- // Set the content-type header('Content-type: image/png'); // Create the image //$im = imagecreatefromjpeg('./user/images/tpls/headbg.jpg'); $im = imagecreatetruecolor(400, 100); // Create some colors $background = imagecolorallocatealpha($im, 60, 60, 60, 127); $black = imagecolorallocate($im, 0, 0, 0); imagealphablending($im, false); imagefilledrectangle($im, 0, 0, 399, 99, $background); // The text to draw $text = 'Tesing ... '; // Replace path by your own font path $font = './zeferinotwo.ttf'; // Add the text imagettftext($im, 40, 0, 10, 40, $black, $font, $text); imagesavealpha($im, true); imagepng($im); imagedestroy($im); Expected result: ---------------- The text "Tesing ..." written on an image Actual result: -------------- http://ww9.ru/test.php PatchesPull Requests
Pull requests:
HistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 13:00:01 2025 UTC |
I don't think it's a font problem. It draws text well when -the background tranparency is swiched off -alphablending is set to true -savealpha is set to false Here is the modifed code: <?php header('Content-type: image/png'); $im = imagecreatetruecolor(400, 100); $background = imagecolorallocatealpha($im, 60, 60, 60, 0)// no tranparency; $black = imagecolorallocate($im, 0, 0, 0); //imagealphablending($im, false); imagefilledrectangle($im, 0, 0, 399, 99, $background); $text = 'Tesing ... '; $font = './zeferinotwo.ttf'; imagettftext($im, 40, 0, 10, 40, $black, $font, $text); //imagesavealpha($im, true); imagepng($im); imagedestroy($im); ?>I've noticed a similar issue with the good old fonts bundled in Windows XP (Arial, Verdana and specially Tahoma). Fonts look good in PHP/5.3.0 and overlap in PHP/5.3.2 (official VB6 thread-safe binaries). Test script: <? $text_ansi = 'áéíóú ÁÉÍÓÚ'; $text_utf8 = utf8_encode('áéíóú ÁÉÍÓÚ'); $font = 'C:/Windows/fonts/tahoma.ttf'; $im = imagecreatetruecolor(400, 60); $white = imagecolorallocate($im, 255, 255, 255); $black = imagecolorallocate($im, 0, 0, 0); imagefilledrectangle($im, 0, 0, 399, 59, $white); imagettftext($im, 15, 0, 10, 25, $black, $font, $text_ansi); imagettftext($im, 15, 0, 10, 55, $black, $font, $text_utf8); header('Content-Type: image/png'); imagepng($im); imagedestroy($im); ?> Rendering sample: http://img408.imageshack.us/img408/5959/php530.png http://img8.imageshack.us/img8/4013/php532.png