PHP uses function_exists to determine the available methods of a function, phpfunction_exists_PHP tutorial

WBOY
Release: 2016-07-13 10:13:46
Original
1076 people have browsed it

php uses function_exists to determine the methods available for functions, phpfunction_exists

The example in this article describes how PHP uses function_exists to determine whether a function is available. Share it with everyone for your reference. The details are as follows:

The function described in this article is used to create a GIF format graphic. The parameter im is the image code created using imagecreate(). The parameter filename can be omitted. If there is no parameter filename, the image will be sent directly to the browser. end, remember to send the header string (header) using content-type: image/gif to the browser before sending the image to ensure smooth transmission of the image. If you want to use a gif image with a transparent background, which is the format of gif89a, you need to use imagecolortransparent() to configure the transparent background first.

Copy code 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
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); //Create image
$bg=imagecolorallocate($im,200,200,200); //Define gray background
$yellow=imagecolorallocate($im,255,255,0); //Define 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 it exists, output it in gif format
header("content-type: image/gif");
imagegif($im);
}
//Determine whether the jpeg function exists
elseif(function_exists("imagejpeg"))
{
//If it exists, output it in jpg format
header("content-type: image/jpeg");
imagejpeg($im, "", 0.5);
}
//Determine whether the png function exists
elseif (function_exists("imagepng"))
{
//If it exists, output it in png format
header("content-type: image/png");
imagepng($im);
}
//Determine whether the wbmp function exists
elseif (function_exists("imagewbmp"))
{
//If it exists, output it in bmp format
header("content-type: image/vnd.wap.wbmp");

The header() function sends raw http headers to the client. It is important to realize that the header() function must be called before any actual output is sent (in PHP 4 and above, you can use output caching to solve this problem):
Copy code The code is as follows:
imagewbmp($im);
}
else
{
//If neither is supported, output the content
die("no image support in this php server");
}

This code determines the support of multiple images, and then outputs the image in the corresponding format.

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

Return value: integer, function type: graphics processing

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/914050.htmlTechArticlephp uses function_exists to determine the method of available functions, phpfunction_exists This article describes the method of using function_exists to determine the available functions of php. Share it with everyone for your reference. Tool...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!