Reputation: 21
I try to add text on image:
$newImg = imagecreatetruecolor($dst_width, $dst_height);
imagealphablending($newImg, false);
imagecopyresampled($newImg, $im, 0, 0, 0, 0, $dst_width, $dst_height, $width, $height);
imagesavealpha($newImg, true);
if(!empty($name)){
$fontSrc = './fonts/DejaVuSans.ttf';//support utf8 and unicode
$font = imageloadfont($fontSrc);
//Couleur des noms
$bg = imagecolorallocatealpha($newImg, 0, 0, 0, 0);
$textcolor = imagecolorallocatealpha($newImg, 255, 255, 255, 1);
//Deplacer les noms
imagestring($newImg, $font, 0, $dst_height - 17, 'שדגשדג', $textcolor);
}
already tried:
header('Content-Type: text/html; charset=utf-8');
imagestring($newImg, 500, 0, $dst_height - 17, utf8_encode('שדגשדגש'), $textcolor);
The issue is when i put text in hebrew(utf8): שדגשד
its show the text on the picture like that:
As you can see its type rubbish text,what is proper way to fix it?
Upvotes: 1
Views: 106
Reputation: 21
Ok finally after deep research and tons of test i finally made it happen and can now use utf8 chars,the issue was imagestring canno't work with utf8 and i should have change to imagettftext and load the ttf font that support utf8 support:
putenv('GDFONTPATH=' . realpath('.'));
$fontGD = './fonts/DejaVuSans';
imagettftext($newImg, 20, 0, 10, 20, $black, $fontGD, 'שגשדג');
Thats it,now working.
Upvotes: 1