PHP output image imagegif, imagejpeg and imagepng function Usage Analysis, imagegifimagepng

Source: Internet
Author: User
Tags imagejpeg

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.