The Imagegif (), imagejpeg (), Imagepng (), and imagewbmp () functions allow images to be exported to a browser or file in GIF, JPEG, PNG, and WBMP formats, respectively.
PHP Output Image
PHP allows images to be exported in different formats:
- Imagegif (): Output images to a browser or file in GIF format
- imagejpeg (): Output images to a browser or file in JPEG format
- Imagepng (): Output images to a browser or file in PNG format
- Imagewbmp (): Output an image to a browser or file in WBMP format
Grammar:
BOOL Imagegif (resource image [, string filename]) bool Imagejpeg (resource image [, string filename [, int quality]]) b Ool Imagepng (Resource image [, string filename]) bool Imagewbmp (resource image [, string filename [, int foreground]] )
Parameter description:
Parameters |
Description |
Image |
The return value of the image resource to be exported, such as imagecreate () or Imagecreatefrom series functions |
FileName |
Optionally, specify the file name of the output image. If omitted, the original image stream will be output directly. |
Quality |
Optional, specify image quality, range from 0 (worst quality, file minimum) to 100 (best quality, File max), default imagejpeg () unique parameter |
Foreground |
Optional, specify foreground color, default foreground color is black, imagewbmp () unique parameter |
Draw an arc and save it to the images directory:
<?phpheader ("Content-type:image/png"), $im = @imagecreate ((), or Die ("Create Image Resource Failed"), $BG = Imagecolorallocate ($im , 204, 204, 204); $red = Imagecolorallocate ($im, 255, 0, 0), Imagearc ($im, N, 0,, $red); Imagepng ($im, "I Mages/circle.png "); Imagedestroy ($im);? >
A circle.png file is generated in the images directory.
PHP output Image imagegif, imagejpeg and Imagepng functions