Chinese characters (Wang Feng)
First, the principle
The GD Library in PHP supports Chinese, but must be passed in UTF-8 format parameters. First of all, the UTF-8 encoding of Chinese characters is obtained.
- Edit the characters you want to display with Notepad in WORD2000 or Window 2000.
- Save the edited text in a file formatted as UTF-8.
- Open the file with a 16-binary editor (such as the PCTools Edit feature), and you will see that there are 16 characters in the open file. A Chinese character occupies three bytes, so you should choose to edit the number of Chinese characters multiplied by 3 bytes of content, the encoding is recorded for later use. such as the code of the Sadie Network is:E8 B5 9B E8 BF AA E7 BD
Second, realize
This example realizes: The www.ccidnet.com image output of the Sadie net. The file name is: ttf.php.
<?php
Define output as Image type
Header ("Content-type:image/gif");
New Image
$pic =imagecreate (240,30);
Define black and white colors
$black =imagecolorallocate ($pic, 0,0,0);
$white =imagecolorallocate ($pic, 255,255,255);
Defining fonts
$font = "C://win2000//fonts//simhei.ttf";
Define output Font string
$STR = Chr (0xe8). chr (0xb5). chr (0x9b). chr (0xe8). chr (0xBF). chr (0xAA). chr (0xe7). chr (0xBD). chr (0x91). Www.ccidnet.com ";
Write TTF text into the diagram
Imagettftext ($pic, 20,0,10,20, $white, $font, $STR);
Create a GIF pattern
Imagegif ($pic);
End graphics, freeing up memory space
Imagedestroy ($pic);
?>
Output as shown in figure:
Description
- The Chinese character is CHR (encoded) by the way of reference. such as Chr (0xe8). chr (0xb5). chr (0x9b) displays Chinese characters.
- Imagettftext (int im, int size, int angle, int x, int y, int col, string fontfile, String text): This function will TTF (TrueType Fonts) word Type text to the picture. The size of the parameter is the dimension of the glyph; angle is the angle of the font. Clockwise calculation, 0 degree level, that is, the direction of three o'clock (from left to right), 90 degrees from the bottom of the text; x,y two parameter is the coordinate value of the text (the origin is the upper-left corner); Col is the color of the word; Fontfile is the font The file name; text is the string content.
- The GD library must be installed to take advantage of the image processing functions in PHP.
- Image reference: Insert directly in the desired place: .
Third, concluding remarks
The GD Library of PHP provides a fairly sophisticated feature that makes it possible to produce a wide variety of graphic images with the full use of its functionality, which enriches the content of the page.