想在图片上画点东西,在网上查到的方法是imagestring,但是呢,不支持中文,发现可以用imagettftext,不同就是imagettftext需要引入字体,在网上找一个或者在自己的电脑上自带的字体找一个就好。
代码如下:
$width = 600;
$height = 650;
header("Content-type: image/gif; charset=utf-8");
$img = imagecreate($width, $height);
$bg_color = imagecolorallocate($img, 0, 0, 0);
$red = imagecolorallocate($img, 255, 0, 0);
$font = "./font/1.ttf";
$sting = '这是第一句话!';
imagettftext($img, 20, 0, 5, 200, $red, $font, $sting);
$sting = '这是第二句话';
imagettftext($img, 20, 0, 5, 300, $red, $font, $sting);
//imagestring ($img , 5 , 300 , 300 , $sting , $red );
for ($i = 0; $i <= 100; $i++) {
for ($j = 0; $j <= 100; $j++) {
$r = M_PI / 50 * $i * (1 - sin(M_PI / 50 * $j)) * 40;
$x = $r * cos(M_PI / 50 * $j) * sin(M_PI / 50 * $i) + $width / 2;
$y = -$r * sin(M_PI / 50 * $j) + $height / 6;
imagesetpixel($img, $x, $y, $red);
}
}
imagegif($img);
imagedestroy($img);
exit;