The PHP verification code is as follows: & lt ;? Phpheader (& #39; Content-type: imagejpeg & #39;); $ width120; $ height40; $ elementarray (& #39; a & #39;, & #39; B & #39;, & #39; c & #39;, & #39; d & #39;, & #39; e & #39;, & #39; f & #39;, & #39; g PHP construct verification code
The code is as follows:
HighlightsImagettftext () method:
ArrayImagettftext(Resource$ Image, Float$ Size, Float$ Angle, Int$ X, Int$ Y, Int$ Color, String$ Fontfile, String$ Text)
-
Image
-
Image resources. See imagecreatetruecolor ().
-
Size
-
Font size. Based on the GD version, the pixel size (GD1) or the point size (GD2) should be specified ).
-
Angle
-
The angle. The value 0 is the text read from left to right. A higher value indicates a counter-clockwise rotation. For example, 90 degrees indicates the text read from the bottom up.
-
X
-
By
X,
YThe coordinates represent the basic points of the first character (probably in the lower left corner of the character ). Unlike imagestring (), x and y define the upper left corner of the first character. For example, "top left" is 0 and 0.
-
Y
-
Y coordinate. It sets the font baseline position, not the bottom of the character.
-
Color
-
Color index. Using a negative color index value can disable anti-aliasing. See imagecolorallocate ().
-
Fontfile
-
Is the path of the TrueType font to be used. Depending on the GD library used by PHP, when
FontfileNo
/Start
. TtfAfter the file name is added, the file name will be searched in the library-defined font path. When the GD Library version is earlier than 2.0.18, a space character instead of a semicolon will be used as the "path separator" for different font files ". When you accidentally use this feature, a warning message is displayed:
Warning: cocould not find/open font. The only solution for affected versions is to move the font to a path without spaces.
In many cases, the font is placed in the same directory of the script. The following tips can alleviate the problems involved.
// Set the enviroment variable for GD
putenv('GDFONTPATH=' . realpath('.'));
// Name the font to be used (note the lack of the .ttf extension)
$font = 'SomeFont';
?>
-
Text
-
Text string. It can contain decimal numeric characters (in the form of: €) to access characters exceeding the position 127 in the font. A UTF-8-encoded string can be passed directly. If a character used in a string is not supported by a font, a hollow rectangle replaces the character.
Imagettftext ()An array containing eight units is returned to indicate the four corners of the text box. The order is the sitting corner, bottom right corner, top right corner, and top left corner. These vertices are irrelevant to the angle of the text. Therefore, the "upper left corner" indicates the upper left corner of the text when the text is viewed horizontally.
Example #1Imagettftext ()Example
The script in this example will generate a white 400x30 pixel PNG image with a black (with gray shadow) Arial font written as "Testing ...".
// Set the content-type
header("Content-type: image/png");
// Create the image
$im = imagecreatetruecolor(400, 30);
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
// The text to draw
$text = 'Testing...';
// Replace path by your own font path
$font = 'arial.ttf';
// Add some shadow to the text
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);
// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>