PHP output image imagegif, imagejpeg and imagepng function Usage Analysis, imagegifimagepng
This article describes how to use the imagegif, imagejpeg, and imagepng functions of PHP output images. We will share this with you for your reference. The details are as follows:
The imagegif (), imagejpeg (), imagepng (), and imagewbmp () functions allow the image to be output to a browser or file in GIF, JPEG, PNG, and WBMP formats respectively.
PHP output image
PHP allows output of images in different formats:
Imagegif (): outputs an image to a browser or file in GIF format.
Imagejpeg (): outputs an image to a browser or file in JPEG format.
Imagepng (): outputs an image to a browser or file in PNG format.
Imagewbmp (): outputs an image to a browser or file in WBMP format.
Syntax:
bool imagegif ( resource image [, string filename] )bool imagejpeg ( resource image [, string filename [, int quality]] )bool imagepng ( resource image [, string filename] )bool imagewbmp ( resource image [, string filename [, int foreground]] )
Parameter description:
Parameters |
Description |
Image |
Image resources to be output, such as the returned values of imagecreate () or imagecreatefrom Functions |
Filename |
(Optional) Name of the output image. If omitted, the original image stream is output directly. |
Quality |
Optional. specifies the image quality, ranging from 0 (worst quality, Minimum File Size) to 100 (best quality, maximum file size). The default value is 75, which is a unique parameter of imagejpeg (). |
Foreground |
(Optional) Specify the foreground color. The default foreground color is black, which is a unique parameter of imagewbmp (). |
Draw an arc and save it to the images directory:
<? Phpheader ("Content-type: image/png"); $ im = @ imagecreate (200,200) or die ("image resource creation failed"); $ bg = imagecolorallocate ($ im, 204,204,204); $ red = imagecolorallocate ($ im, 255, 0, 0); imagearc ($ im, 100,100,150,150, 0,360, $ red); imagepng ($ im, "images/circle.png"); imagedestroy ($ im);?>
A circle.png file is generated under the images directory.