Php generates text code on the image. In the php Tutorial, if you want to use its image processing function, you must go to php. enable the gd Library in ini, * send the header file header (content-type: imagepng); create an image. if it fails to be output to the php Tutorial, you must use the image processing function in php. enable the gd Library in ini,
*/
// Send the header file
Header ("content-type: image/png ");
// Create an image. if the output fails
$ Im = @ imagecreate (150,50) or die ("cannot initialize new gd image stream ");
// Define the background color
$ Background_color = imagecolorallocate ($ instant, 255,255,255 );
// Define the text color
$ Text_color = imagecolorallocate ($ im, 233,14, 91 );
// Draw a file on the image
Imagestring ($ im, 3,5, 5, "hello world", $ text_color );
// Output image file
Imagepng ($ im );
// Destroy the image
Imagedestroy ($ im );
/*
The code execution result 22.5 is as follows:
*/
// 2. the image proportion is reduced.
// Define a file
Using filename='1.jpg ';
// Define the zoom percentage
$ Percent = 0.5;
// Output header file
Header ('content-type: image/jpeg ');
// Obtain the new size
List ($ width, $ height) = getimagesize ($ filename );
$ Newwidth = $ width * $ percent;
$ Newheight = $ height * $ percent;
// Create a graphic area and load the image
$ Thumb = imagecreatetruecolor ($ newwidth, $ newheight );
$ Source = imagecreatefromjpeg ($ filename );
// Adjust the size again
Imagecopyresized ($ thumb, $ source, 0, 0, 0, 0, $ newwidth, $ newheight, $ width, $ height );
// Output image
Imagejpeg ($ thumb );
/*
Run the code to scale the original image by 50% and output the new image.
*/
// Write text on the image
// Define content
$ Data = 'ivborw0kggoaaaansuheugaaabwaaaascamaaab/2u7waaaabl '.
'Bmveuaaad // + l2z/daaaasuleqvr4xqwquqoaiaxc2/0vxzdr '.
'Ex4ijtrkb7lobnustxsb0jixiamssqnwlsv + wulf4avk9flq2r '.
'8a5hse35q3eo2xp1a1wqkzsgetvdtkdqaaaabjru5erkjggg = ';
// Base64 encode the content
$ Data = base64_decode ($ data );
// Create an image based on the string
$ Im = imagecreatefromstring ($ data );
If ($ im! = False)
{
// If the image is created successfully, the image is output.
Header ('content-type: image/png ');
Imagepng ($ im );
}
Else
{
// If creation fails, the output content
Echo 'a error occured .';
}
/*
The code execution result 22.4 is as follows:
*/
// Write text on the image
Header ("content-type: image/png ");
// Create an image. if the output fails
$ Im = @ imagecreate (100,50) or die ("cannot initialize new gd image stream ");
// Define the background color
$ Background_color = imagecolorallocate ($ instant, 255,255,255 );
// Define the text color
$ Text_color = imagecolorallocate ($ im, 233,14, 91 );
// Draw a file on the image
Imagestring ($ im, 1, 5, 5, "a simple text string", $ text_color );
// Output image file
Imagepng ($ im );
// Destroy the image
Imagedestroy ($ im );
/*
Execute this code to generate a jpeg image.
And output the specified string
*/
Response, * /// send the header file header (content-type: image/png); // create an image, if the output fails...