PHP GD Library generated several functions of the image summary, PHPGD
After using the functions provided in the GD library to dynamically draw the finished image, you need to output to the browser or save the image. In PHP, you can animate a canvas that is finished dynamically, producing GIF, JPEG, PNG, and wbmp four image formats directly. You can generate images of these formats by calling the following four functions:
Copy the Code code as follows:
BOOL Imagegif (Resource $image [, String $filename])//output image in GIF format
BOOL Imagejpeg (Resource $image [, String $filename [, int $quality]]//output image in JPEG format
BOOL Imagepng (Resource $image [, String $filename])//output image in PNG format
BOOL Imagewbmp (Resource $image [, String $filename [, int $foreground]]//output image in wbmp format
The above four functions are used similarly, the first two parameters are used the same. The first parameter, $image, is the required option, and is the image reference handle described earlier. If these functions provide additional parameters, the original image is streamed directly from the access, and the dynamic output image is displayed in the browser's use. But be sure to send header information before the output, using the header () function to tell the browser to parse the received content using the correct MIME type to let it know that we are sending the image instead of the HTML that looks like text. The following code snippet writes out a better-ported PHP program by automatically detecting the type of image supported by the GD library. As shown below:
Copy the Code code as follows:
<?php
if (function_exists ("Imagegif")) {//Determine if the function that generated the GIF format image exists
Header ("Content-type:image/gif"); Send header information set MIME type to Image/gif
Imagegif ($im); Output an image to a browser in GIF format
}elseif (function_exists ("Imageipeg")) {
Header ("Content-type:image/jpeg");
Imagejpeg ($im, "", 0.5);
}elseif (function_exists ("Imagepng")) {
Header ("Content-type:image/png");
Imagepng ($im);
}elseif (function_exists ("Imagewbmp")) {
Header ("Content-type:image/wbmp");
Imagewbmp ($im);
}else{
Die ("Image not supported in PHP server");
}
?>
If you want to save the dynamically drawn image of PHP on the local server, you must specify a file name string in the second optional parameter. This not only does not output the image directly to the browser, nor does it need to send header information using the header () function. If you use the imagejpeg () function to generate an image in JPEG format, you can also specify the quality of the JPEG format image through the third optional parameter $quality, which can provide an integer value from 0 (worst quality, but smallest file) to 100 (highest quality, file Max). The default value is 75. You can also provide a third optional parameter $forground for the function imagewbmp (), specify the foreground color of the image, and the default color value is black.
http://www.bkjia.com/PHPjc/914045.html www.bkjia.com true http://www.bkjia.com/PHPjc/914045.html techarticle PHP GD Library generated several functions of the image summary, PHPGD using the functions provided in the GD library to draw the finished image dynamically, you need to output to the browser or save the image. In PHP, ...