PHP pictures to add text (text watermark) (imagestring does not support Chinese, instead imagettftext)

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/qq_41399976/article/details/101431627

Want to draw something on the image, the method found on the Internet is imagestring, but it does not support Chinese, can be found imagettftext, is imagettftext need to introduce different fonts, or find a computer on their own fonts online find a fine.

code show as below:

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

Guess you like

Origin blog.csdn.net/qq_41399976/article/details/101431627