linux下出现乱码,加上编码转换就可以了。
$im = imagecreatefromjpeg('images/img.jpg');
$font = 'msyh.ttc'; //对应的字体文件
$white = imagecolorallocate($im,255,255,255); //字体颜色 RGB
$fontSize = 24; //字体大小
$circleSize = 0; //旋转角度
$left = 100; //左边距
$top = 100; //顶边距
$str = "你好!"; //要加的文字
$str = mb_convert_encoding($str, "html-entities", "utf-8");
imagettftext($im, $fontSize, $circleSize, $left, $top, $white, $font, $str);
header('Content-type: image/png');
//imagejpeg($im,'test.jpg');
imagejpeg($im);
imagedestroy($im);