图像字符串垃圾文本问题


Imagestring rubbish text issue

>我尝试在图像上添加文本:

$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)输入文本时:שדגשד它像这样显示图片上的文本:

图像示例

如您所见,其类型垃圾文本,正确的解决方法是什么?

好的,

经过深入研究和大量测试,我终于实现了它,现在可以使用 utf8 字符,问题是图像字符串无法与 utf8 一起使用,我应该更改为 imagettftext 并加载支持 utf8 的 TTF 字体:

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

就是这样,现在正在工作。