linux下出现乱码,加上编码转换就可以了。
$im = imagecreatefromjpeg(‘images/img.jpg’);
$font = ‘msyh.ttc’; //对应的字体文件
w
h
i
t
e
=
i
m
a
g
e
c
o
l
o
r
a
l
l
o
c
a
t
e
(
white = imagecolorallocate(
white=imagecolorallocate(im,255,255,255); //字体颜色 RGB
$fontSize = 24; //字体大小
$circleSize = 0; //旋转角度
$left = 100; //左边距
$top = 100; //顶边距
$str = “你好!”; //要加的文字
s
t
r
=
m
b
c
o
n
v
e
r
t
e
n
c
o
d
i
n
g
(
str = mb_convert_encoding(
str=mbconvertencoding(str, “html-entities”, “utf-8”);
imagettftext($im, $fontSize, $circleSize, $left, $top, $white, $font, $str);
header(‘Content-type: image/png’);
//imagejpeg(
i
m
,
′
t
e
s
t
.
j
p
g
′
)
;
i
m
a
g
e
j
p
e
g
(
im,'test.jpg'); imagejpeg(
im,′test.jpg′);imagejpeg(im);
imagedestroy($im);