If you want to use its image processing function in the php tutorial, you must open the gd library in php.ini,
*/
//Send header file
header("content-type: image/png");
//Create image, output content if failed
$im=@imagecreate(150,50) or die("cannot initialize new gd image stream");
//Define background color
$background_color=imagecolorallocate($im,255,255,255);
//Define text color
$text_color=imagecolorallocate($im,233,14,91);
//Draw the file on the image
imagestring($im,3,5,5,"hello world",$text_color);
//Output image file
imagepng($im);
//Destroy image
imagedestroy($im);
/*
The execution result of this code is shown in Figure 22.5:
*/
//2 pictures are scaled down
//Define a file
$filename='1.jpg';
//Define zoom percentage
$percent=0.5;
//Output header file
header('content-type: image/jpeg');
//Get new size
list($width,$height)=getimagesize($filename);
$newwidth=$width * $percent;
$newheight=$height * $percent;
//Create a graphics area and load the image
$thumb=imagecreatetruecolor($newwidth,$newheight);
$source=imagecreatefromjpeg($filename);
//Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
//Output image
imagejpeg($thumb);
/*
Executing this code will scale the original image by 50% and output it as a new image
*/
//Write text on the picture
//Definition content
$data='ivborw0kggoaaaansuheugaaabwaaaascamaaab/2u7waaaabl'.
'bmveuaaad///+l2z/daaaasuleqvr4xqwquqoaiaxc2/0vxzdr'.
'ex4ijtrkb7lobnustxsb0jixiamssqnwlsv+wulf4avk9flq2r'.
‘8a5hse35q3eo2xp1a1wqkzsgetvdtkdqaaaabjru5erkjggg==’;
//base64 encode the content
$data=base64_decode($data);
//Create a new image based on the string
$im=imagecreatefromstring($data);
if($im!== false)
{
//If successfully created, output the image
header('content-type: image/png');
imagepng($im);
}
else
{
//If creation fails, output content
echo 'an error occurred.';
}
/*
The execution result of this code is shown in Figure 22.4:
*/
//Write text on the picture
header("content-type: image/png");
//Create image, output content if failed
$im=@imagecreate(100,50) or die("cannot initialize new gd image stream");
//Define background color
$background_color=imagecolorallocate($im,255,255,255);
//Define text color
$text_color=imagecolorallocate($im,233,14,91);
//Draw the file on the image
imagestring($im,1,5,5,"a simple text string",$text_color);
//Output image file
imagepng($im);
//Destroy image
imagedestroy($im);
/*
Executing this code will generate a jpeg image.
And output the specified string
*/