Php uses function_exists to determine the available function methods. phpfunction_exists_PHP tutorial-php Tutorial

Source: Internet
Author: User
Tags imagejpeg
Php uses function_exists to determine the available methods of the function, phpfunction_exists. Php uses function_exists to determine whether a function is available. phpfunction_exists this article describes how php uses function_exists to determine whether a function is available. Share it with you for your reference. Php uses function_exists to determine the available function methods. phpfunction_exists

This example describes how php uses function_exists to determine the available function. Share it with you for your reference. The details are as follows:

The function described in this article is used to create a gif image. the im parameter is the image code created using imagecreate (). The filename parameter can be omitted, the image will be sent directly to the browser. remember to send the header string (header) using content-type: image/gif to the browser before sending the image, so as to transmit the image smoothly. To use a gif image with a transparent background, that is, the gif89a format, you must first use imagecolortransparent () to configure the transparent background.

The code is 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
, 20, // coordinates of the first vertex
50, 40, // coordinates of the first vertex
10, 10 // coordinates of the first vertex
);
$ Im = imagecreatetruecolor (250,250); // create an image
$ Bg = imagecolorallocate ($ im, 200,200,200); // defines the gray background
$ Yellow = imagecolorallocate ($ im, 255,255, 0); // defines the yellow foreground
Imagefilledpolygon ($ im, $ values, 6, $ yellow); // draw a polygon
Header ('content-type: image/png ');
// Determine whether the gif function exists
If (function_exists ("imagegif "))
{
// If yes, output in gif format
Header ("content-type: image/gif ");
Imagegif ($ im );
}
// Determine whether the jpeg function exists
Elseif (function_exists ("imagejpeg "))
{
// If yes, output in jpg format
Header ("content-type: image/jpeg ");
Imagejpeg ($ im, "", 0.5 );
}
// Determine whether the png function exists
Elseif (function_exists ("imagepng "))
{
// If yes, output in png format
Header ("content-type: image/png ");
Imagepng ($ im );
}
// Determine whether the wbmp function exists
Elseif (function_exists ("imagewbmp "))
{
// If yes, output in bmp format
Header ("content-type: image/vnd. wap. wbmp ");


The header () function sends the original http header to the client. it is important to realize that the header () must be called before any actual output is sent () function (in php 4 and later versions, you can use the output cache to solve this problem ):

The code is as follows:

Imagewbmp ($ im );
}
Else
{
// Output Content if none of them are supported
Die ("no image support in this php server ");
}

This code identifies multiple types of image support and then outputs the image in the corresponding format.

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

Return value: integer, function type: Graphic Processing

I hope this article will help you with PHP programming.

Examples in this article describes how php uses function_exists to determine whether a function is available. Share it with you for your reference. With...

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.