2016-07-07 60 views
1

我尝试在图片添加文字:和imagestring垃圾文本问题

$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); 
    } 

已经尝试过:

header('Content-Type: text/html; charset=utf-8'); 
imagestring($newImg, 500, 0, $dst_height - 17, utf8_encode('שדגשדגש'), $textcolor); 

的问题是,当我在希伯来文(UTF8)把文本:שדגשד其显示文本图片上的那样:

image example

正如你可以看到它的类型垃圾文本,修复它的正确方法是什么?

+1

我的第一个猜测是用过的字体不支持unicode。 – Eiko

+0

也试过,我现在编辑。 – Roasls

回答

1

好最后深入的研究和测试吨的我终于成为现实,现在可以使用UTF-8字符,的问题是和imagestring canno't工作,UTF8,我应该有变化imagettftext并加载TTF字库后支持utf8支持:

putenv('GDFONTPATH=' . realpath('.')); 
    $fontGD = './fonts/DejaVuSans'; 
    imagettftext($newImg, 20, 0, 10, 20, $black, $fontGD, 'שגשדג'); 

这就是它,现在工作。