php function_exists determines the available code of the function

高洛峰
Release: 2016-11-29 13:11:56
Original
1087 people have browsed it

Content description: This function 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 to the browser. 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 the GIF graph with a transparent background, that is, the format of the GIF89A, you need to use ImageColortransparent () to configure the transparent background .

$ values ​​= Array (

40,50, // The coordinates of the first vertex of 20,240, 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 the yellow foreground

imagefilledpolygon($im,$values,6,$yellow); //Draw the 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);

}

//Judge whether the wbmp function exists

elseif (function_exists("imagewbmp"))

{//Open source code phpfensi.com

//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 higher version, you can use output caching to solve this problem):

*/

imagewbmp($im);

}

else

{

//If neither is supported, the output content

die( "no image support in this php server");

}

/*

The execution result of this code is similar to code 22-25. The difference is that this code determines the support of multiple images, and then uses the corresponding Format output image.

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

Return value: integer, function type: graphics processing

Related labels:
php
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