PHP.ini change; extension=php_gd2.dll
Creating an image in PHP should be done in four steps:
• Create a background image • Draw a graphic on the background or enter text • Output final graphics • Clear all resources
<?php
$width = 200; Image width
$height = 400; Image Height
$img = Imagecreatetruecolor ($width, $height);
?>
Read an existing image file by Imagecreatefrompng (), Imagecreatejpeg (), or imagecreatefromgif (), then filter it and add additional images to it.
<?php
$imgTemp = imagecreatefrompng (' abc.png ');
?>
<?php
$width = 200; Image width
$height = 400; Image Height
$img = Imagecreatetruecolor ($width, $height);
$white = Imagecolorallocate ($img, 255, 255, 255); RGB value
$blue = imagecolorallocate ($img, 0, 0, 64);
Imagefill ($img, 0, 0, $blue); Fill $blue in the background map
Imageline ($img, 0, 0, $width, $height, $white); /* Here there are 2 pairs of coordinates, "0, 0" is the coordinates of the starting point, and $width, $height is the coordinates of the end, the last parameter is the color. */
Imagestring ($img, 3, +, ' abc ', $white);//write a string on the image
?>
<?php
$width = 200; Image width
$height = 400; Image Height
$img = Imagecreatetruecolor ($width, $height);
$white = Imagecolorallocate ($img, 255, 255, 255); RGB value
$blue = imagecolorallocate ($img, 0, 0, 64);
Imagefill ($img, 0, 0, $blue); Fill $blue in the background map
Imageline ($img, 0, 0, $width, $height, $white); /* Here there are 2 pairs of coordinates, "0, 0" is the coordinates of the starting point, and $width, $height is the coordinates of the end, the last parameter is the color. */
Imagestring ($img, 3, +, ' abc ', $white);//write a string on the image
Header (' content-type:image/png '); Specifies the MIME type of the image
Imagepng ($IMG); Output image data
?>
Similarly, if you want to eventually output a JPEG image, you can use imagejpeg () to output it, and also replace the header () function parameter with Image/jpeg.
In summary, we are sending the image directly to the browser, if we want to automatically create the image generated file, you can add the second parameter in the Imagepng () function, this parameter is the name of the file you want to generate, such as logo.png. Note that the file suffix name remains in the format, and the filename is enclosed in quotation marks.
-------------------------
Freeing and destroying resources
<?php
$width = 200; Image width
$height = 400; Image Height
$img = Imagecreatetruecolor ($width, $height);
$white = Imagecolorallocate ($img, 255, 255, 255); RGB value
$blue = imagecolorallocate ($img, 0, 0, 64);
Imagefill ($img, 0, 0, $blue); Fill $blue in the background map
Imageline ($img, 0, 0, $width, $height, $white); /* Here there are 2 pairs of coordinates, "0, 0" is the coordinates of the starting point, and $width, $height is the coordinates of the end, the last parameter is the color. */
Imagestring ($img, 3, +, ' abc ', $white);//write a string on the image
Header (' content-type:image/png '); Specifies the MIME type of the image
Imagepng ($IMG); Output image data
Imagedestroy ($IMG); Release and Destroy
?>
Call an automatically generated image
Summarize:
Create a background Image: Imagecreatetruecolor ()
Drawing or entering text on the background: Imagecolorallocate (), Imagefill (), Imageline (), imagestring ()
Output Final Graphics: header (), Imagepng ()
Clear All resources: Imagedestroy ()
PHP operation Image (GD function library)