dsaba Posted March 28, 2007 Share Posted March 28, 2007 I have problems using this function and get it to display the characters correctly here is the text requirement taken from php.net text The text string. May include decimal numeric character references (of the form: €) to access characters in a font beyond position 127. The hexadecimal format (like ©) is supported as of PHP 5.2.0. Strings in UTF-8 encoding can be passed directly. Named entities, such as ©, are not supported. Consider using html_entity_decode() to decode these named entities into UTF-8 strings (html_entity_decode() supports this as of PHP 5.0.0). If a character is used in the string which is not supported by the font, a hollow rectangle will replace the character. I am using font davidtr.ttf here are some pics from the character map from windows xp: -------------------------------------------------------------------- as you can see from the pics its I now understand that the font davidtr.ttf supports 1. unicode (utf- 2. Hebrew (DOS) aka: DOS-862 3. Hebrew (windows) aka: windows- 1255 so according to the php manual if I try to pass any character in any of the fonts supported charsets, then it should write it with the font just fine if not: "If a character is used in the string which is not supported by the font, a hollow rectangle will replace the character. " so I ran many different tests to to test this fact that the font should be able to correctly display characters in any of those above supported charsets in order to run the test I need to successfully change a string's charset in the php script I set this with both of these things: 1. I set this html tag <meta http-equiv="Content-Type" content="text/html; charset=windows-1255" /> 2. I SAVE the .PHP file in dreamweaver in the charset, look at the picture below ----------------------------------------------------------------------------------------- Additionally there is a handy function called mb_check_encoding(); , however it only works in php 5 or in php 4.4.3 which has the extra mb library installed, and I have neither of these, however I tried it on a friends server who does have php 5 and the encodings did check out, in the code snippets I provide below i have commented out the mb() function but if you have the library installed you're welcome to uncomment it and use it THE GLORIOUS TESTS ------------------------ for charset utf-8 aka: unicode http://p2mcity.freehostia.com/codetest-utf8.php SUCCESSFULL <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>testcode--</title> </head> <body> <?php $flowerurl = "http://auslantuition.csse.uwa.edu.au/images/avatarTN.JPG"; $flower = imagecreatefromjpeg($flowerurl); list($width_orig, $height_orig) = getimagesize($flowerurl); $avatar = imagecreatetruecolor(70, 67); imagecopyresampled($avatar, $flower, 0, 0, 0, 0, 70, 67, $width_orig, $height_orig); $backgroundurl = "http://p2mhunt.freehostbr.com/images/background.png"; $background = imagecreatefrompng($backgroundurl); imagecopymerge($background, $avatar, 5, 28, 0, 0, 70, 67, 100); $white = imagecolorallocate($background, 255, 255, 255); $fontfile = "davidtr.ttf"; $string = "יצור מושלם Perfect Creature"; /*if ((mb_check_encoding($string, "utf-8")) == TRUE) { echo 'the string is '.$string.' it is encoded in utf-8 by the html meta tag and it is saved in utf-8 in dreamweaver,<br>'; } else { echo 'the string: '.$string.' it is NOT ENCODED in utf-8<br>'; echo '<br>'; } */ imagettftext($background, 12, 0, 3, 17, $white, $fontfile, $string); imagepng($background, "usercard.png"); imagedestroy($background); imagedestroy($avatar); imagedestroy($flower); ?> <img src="usercard.png" /> </body> </html> -------------------------------------------- for charset DOS-862 aka: Hebrew (DOS) http://p2mcity.freehostia.com/codetest-dos862.php UNSUCCESSFULL <body> <?php $flowerurl = "http://auslantuition.csse.uwa.edu.au/images/avatarTN.JPG"; $flower = imagecreatefromjpeg($flowerurl); list($width_orig, $height_orig) = getimagesize($flowerurl); $avatar = imagecreatetruecolor(70, 67); imagecopyresampled($avatar, $flower, 0, 0, 0, 0, 70, 67, $width_orig, $height_orig); $backgroundurl = "http://p2mhunt.freehostbr.com/images/background.png"; $background = imagecreatefrompng($backgroundurl); imagecopymerge($background, $avatar, 5, 28, 0, 0, 70, 67, 100); $white = imagecolorallocate($background, 255, 255, 255); $fontfile = "davidtr.ttf"; $string = "יצור מושלם Perfect Creature"; /*if ((mb_check_encoding($string, "utf-8")) == TRUE) { echo 'the string is '.$string.' it is encoded in utf-8 by the html meta tag and it is saved in utf-8 in dreamweaver,<br>'; } else { echo 'the string: '.$string.' it is NOT ENCODED in utf-8<br>'; echo '<br>'; } */ imagettftext($background, 12, 0, 3, 17, $white, $fontfile, $string); imagepng($background, "usercard.png"); imagedestroy($background); imagedestroy($avatar); imagedestroy($flower); ?> <img src="usercard.png" /> </body> </html> -------------------------------------------- for charset windows- 1255 aka: Hebrew (windows) http://p2mcity.freehostia.com/codetest-windows.php UNSUCCESFULL <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1255" /> <title>Untitled Document</title> </head> <body> <?php $flowerurl = "http://auslantuition.csse.uwa.edu.au/images/avatarTN.JPG"; $flower = imagecreatefromjpeg($flowerurl); list($width_orig, $height_orig) = getimagesize($flowerurl); $avatar = imagecreatetruecolor(70, 67); imagecopyresampled($avatar, $flower, 0, 0, 0, 0, 70, 67, $width_orig, $height_orig); $backgroundurl = "http://p2mhunt.freehostbr.com/images/background.png"; $background = imagecreatefrompng($backgroundurl); imagecopymerge($background, $avatar, 5, 28, 0, 0, 70, 67, 100); $white = imagecolorallocate($background, 255, 255, 255); $fontfile = "davidtr.ttf"; $string = "יצור מושלם Perfect Creature"; /*if ((mb_check_encoding($string, "utf-8")) == TRUE) { echo 'the string is '.$string.' it is encoded in utf-8 by the html meta tag and it is saved in utf-8 in dreamweaver,<br>'; } else { echo 'the string: '.$string.' it is NOT ENCODED in utf-8<br>'; echo '<br>'; } */ imagettftext($background, 12, 0, 3, 17, $white, $fontfile, $string); imagepng($background, "usercard.png"); imagedestroy($background); imagedestroy($avatar); imagedestroy($flower); ?> <img src="usercard.png" /> </body> </html> ------------------------------------------------- for charset iso-8859-8-i aka: Hebrew (ISO Logical) http://p2mcity.freehostia.com/codetest-isological.php UNSUCCESSFUL <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-8-i" /> <title>Untitled Document</title> </head> <body> <?php $flowerurl = "http://auslantuition.csse.uwa.edu.au/images/avatarTN.JPG"; $flower = imagecreatefromjpeg($flowerurl); list($width_orig, $height_orig) = getimagesize($flowerurl); $avatar = imagecreatetruecolor(70, 67); imagecopyresampled($avatar, $flower, 0, 0, 0, 0, 70, 67, $width_orig, $height_orig); $backgroundurl = "http://p2mhunt.freehostbr.com/images/background.png"; $background = imagecreatefrompng($backgroundurl); imagecopymerge($background, $avatar, 5, 28, 0, 0, 70, 67, 100); $white = imagecolorallocate($background, 255, 255, 255); $fontfile = "davidtr.ttf"; $string = "יצור מושלם Perfect Creature"; /*if ((mb_check_encoding($string, "utf-8")) == TRUE) { echo 'the string is '.$string.' it is encoded in utf-8 by the html meta tag and it is saved in utf-8 in dreamweaver,<br>'; } else { echo 'the string: '.$string.' it is NOT ENCODED in utf-8<br>'; echo '<br>'; } */ imagettftext($background, 12, 0, 3, 17, $white, $fontfile, $string); imagepng($background, "usercard.png"); imagedestroy($background); imagedestroy($avatar); imagedestroy($flower); ?> <img src="usercard.png" /> </body> </html> --------------------------------------------------- for charset iso-8859-8 aka: Hebrew (ISO Visual) http://p2mcity.freehostia.com/codetest-isovisual.php UNSUCCESSFUL <body> <?php $flowerurl = "http://auslantuition.csse.uwa.edu.au/images/avatarTN.JPG"; $flower = imagecreatefromjpeg($flowerurl); list($width_orig, $height_orig) = getimagesize($flowerurl); $avatar = imagecreatetruecolor(70, 67); imagecopyresampled($avatar, $flower, 0, 0, 0, 0, 70, 67, $width_orig, $height_orig); $backgroundurl = "http://p2mhunt.freehostbr.com/images/background.png"; $background = imagecreatefrompng($backgroundurl); imagecopymerge($background, $avatar, 5, 28, 0, 0, 70, 67, 100); $white = imagecolorallocate($background, 255, 255, 255); $fontfile = "davidtr.ttf"; $string = "יצור מושלם Perfect Creature"; /*if ((mb_check_encoding($string, "utf-8")) == TRUE) { echo 'the string is '.$string.' it is encoded in utf-8 by the html meta tag and it is saved in utf-8 in dreamweaver,<br>'; } else { echo 'the string: '.$string.' it is NOT ENCODED in utf-8<br>'; echo '<br>'; } */ imagettftext($background, 12, 0, 3, 17, $white, $fontfile, $string); imagepng($background, "usercard.png"); imagedestroy($background); imagedestroy($avatar); imagedestroy($flower); ?> <img src="usercard.png" /> </body> </html> --------------------------------------------------- The last two (iso logical, and iso visual) aren't supported in the character map, but I tried them anyways since they are another type of hebrew charset. As you can see by the tests only one test worked, and the rest failed (meaning the hebrew showed up as blank white rectangles) ONLY UTF-8 charset worked, even though according to the PHP manual and the character map for the font, which i provided references, windows-1255 and dos-862 SHOULD HAVE ALSO WORKED as you can tell by my lengthy description and all my efforts for everyone to understand what exactly is my problem and what is my viewpoint....... that I am quite serious in my efforts to solve this problem My question is how do I write with the font using the windows-1255 and dos-862 charsets???? -thanks for reading, and thanks for trying Link to comment https://forums.phpfreaks.com/topic/44577-using-the-imagetfftext-function/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.