PHP uses Function_exists to determine the methods available _php tips

Source: Internet
Author: User
Tags imagejpeg php server

This example describes the methods that PHP uses to determine the Function_exists function. Share to everyone for your reference. Specifically as follows:

The functions described in this paper are used to create a GIF format graphics, parameter im for the use of Imagecreate () created by the picture code, parameter filename can be omitted, if there is no this parameter filename, the picture will be sent directly to the browser side, remember to send out the picture before the use of Content-type:image/gif Header string (header) to the browser end to transfer pictures smoothly. To use a transparent background gif, which is the gif89a format, you need to configure the transparent background with imagecolortransparent () first.

Copy Code code as follows:
$values =array (
40,50,//coordinates of the first vertex
20,240,//coordinates of the first vertex
60,60,//coordinates of the first vertex
240,20,//coordinates of the first vertex
50,40,//coordinates of the first vertex
10,10//coordinates of the first vertex
);
$im =imagecreatetruecolor (250,250); Creating images
$BG =imagecolorallocate ($im, 200,200,200); Define a gray background
$yellow =imagecolorallocate ($im, 255,255,0); Define yellow foreground
Imagefilledpolygon ($im, $values, 6, $yellow); Draw a polygon
Header (' content-type:image/png ');
To determine whether a GIF function exists
if (function_exists ("Imagegif"))
{
If present, output in GIF format
Header ("Content-type:image/gif");
Imagegif ($im);
}
To determine whether a JPEG function exists
ElseIf (function_exists ("imagejpeg"))
{
If present, output in JPG format
Header ("Content-type:image/jpeg");
Imagejpeg ($im, "" ", 0.5);
}
To determine if a PNG function exists
ElseIf (function_exists ("Imagepng"))
{
If present, output in PNG format
Header ("Content-type:image/png");
Imagepng ($im);
}
To determine if the Wbmp function exists
ElseIf (function_exists ("Imagewbmp"))
{
If present, output in BMP format
Header ("Content-type:image/vnd.wap.wbmp");

The header () function sends the original HTTP header to the client, and it is important to recognize that the header () function must be invoked before any actual output is sent (in PHP 4 and later, you can use output caching to solve the problem):
Copy Code code as follows:
Imagewbmp ($im);
}
Else
{
If none is supported, the output content
Die ("No image support in this PHP server");
}

The code judges multiple image support and then outputs the image in the appropriate format.

Syntax: int imagegif (int im, string [filename]);

Return value: Integer, Function type: graphics processing

I hope this article will help you with your 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.