PHP drawing on the image of the method of writing Chinese and English,
The example of this paper is about how to write Chinese and English on the image of PHP drawing. Share to everyone for your reference. Specific as follows:
The first method, can only write in English, Chinese will appear garbled
Copy the Code code as follows: <?php
1. Create a canvas
$im = Imagecreatetruecolor (300,200);//Create a new true color image, the default background is black, return the image identifier. There is also a function imagecreate has not been recommended for use.
$red = Imagecolorallocate ($im, 255,0,0);
2. Writing
$str = "Hello,world";
Imagestring ($im, 5,30,60, $str, $red);//Parameter Description: 5-refers to the size of the text. Function Imagestring cannot write Chinese
3. Output image
Header ("Content-type:image/png");
Imagepng ($im);//output to page. If there is a second argument [, $filename], the image is saved
4. Destroy the image and release the memory
Imagedestroy ($im);
?>
The second way: Write Chinese
Copy the Code code as follows: <?php
1. Create a canvas
$im = Imagecreatetruecolor (300,200);//Create a new true color image, the default background is black, return the image identifier. There is also a function imagecreate has not been recommended for use.
$red = Imagecolorallocate ($im, 255,0,0);
2. Writing
$str = Iconv ("gb2312", "Utf-8", "Beijing, you early!") Hello,world ");//file format for GBK, and here to uft-8 format, in order to normal output, otherwise it is garbled. Indicates unknown
Imagettftext ($im, 12,rand (0,20), 20,100, $red, "Simhei.ttf", $str);
3. Output image
Header ("Content-type:image/png");
Imagepng ($im);//output to page. If there is a second argument [, $filename], the image is saved
4. Destroy the image and release the memory
Imagedestroy ($im);
?>
The Imagettftext () function is much stronger than the imagestring () function, and is manifested in these aspects:
(1) imagettftext () can output Chinese and English, you can specify a font, imagestring () can only output English, only the default font is used.
(2) imagettftext () font size can be infinitely large, imagestring () font is only the size of the number.
(3) The font of the Imagettftext () output can be changed from the angle; imagestring () can only be output horizontally.
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/947208.html www.bkjia.com true http://www.bkjia.com/PHPjc/947208.html techarticle PHP Drawing on the image of the method of writing Chinese and English, this article describes the PHP drawing in the picture to write Chinese and English methods. Share to everyone for your reference. Specific as follows: The first ...