PHP output Image imagegif, imagejpeg and imagepng function usage Analysis _php skill

Source: Internet
Author: User
Tags imagejpeg

The example of this article describes the PHP output image imagegif, imagejpeg and imagepng function usage. Share to everyone for your reference, specific as follows:

The Imagegif (), imagejpeg (), Imagepng (), and imagewbmp () functions allow images to be exported to browsers or files in GIF, JPEG, PNG, and WBMP formats, respectively.

PHP Output Image

PHP allows images to be exported in different formats:

Imagegif (): Prints an image to a browser or file in GIF format
imagejpeg (): Output the image to a browser or file in JPEG format
Imagepng (): Output the image 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 ])
bool Imagepng (resource image [, string filename])
bool Imagewbmp (resource image [, string filename [, in T foreground]])

Parameter description:

Parameters Description
Image The return value of an image resource, such as a imagecreate () or Imagecreatefrom series function, that you want to output
FileName Optionally, specify the file name of the output image. If omitted, the original image stream is directly exported.
Quality Optional, specify image quality, range from 0 (worst quality, file minimum) to 100 (best quality, File max), default, imagejpeg () unique parameter
Foreground Optionally, specify the foreground color, the default foreground color is black, imagewbmp () unique parameter

Draw an arc and save it to the images directory:

<?php
Header ("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, 0, 360, $red);
Imagepng ($im, "images/circle.png");
Imagedestroy ($im);
? >

A circle.png file is generated in the images directory.

More about PHP Interested readers can view the site topics: "PHP graphics and pictures Operating skills summary", "PHP file Operation Summary", "PHP Array" operation Skills Encyclopedia, "PHP Basic Grammar Introductory Course", "PHP Operations and Operator Usage Summary", " Introduction to PHP object-oriented programming program, "PHP Network Programming Skills Summary", "PHP string (String) Usage Summary", "Php+mysql database Operation Tutorial" and "PHP common database Operation Skills Summary"

I hope this article will help you with the PHP program design.

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.