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.