Analysis of PHP plotting technology. 1. image format: currently, common image formats for website development include gif, jpgjpeg, and png ..... difference: GIF images have a high compression rate, but only 256 colors can be displayed, which may cause loss of colors.
1. image format: currently, common image formats for website development include gif, jpg/jpeg, and png .....
Differences:
• Gif images have a high compression rate, but only 256 colors can be displayed, which may lead to loss of colors. animations can be displayed.
• Jpg/jpeg images have a high compression ratio (lossy compression), which can be displayed with smaller files and used more on webpages.
• Png this format combines the advantages of gif and jpg, but the disadvantage is that animation cannot be displayed.
2. drawing through PHP programming
The code is as follows:
// Prerequisites for drawing technology: enable the gd library in the php. ini file
// Create a canvas. the default background is black.
$ Img = imagecreatetruecolor (0, 400,300 );
// Draw various images
// Create a color
$ Background = imagecolorallocate ($ img, 255, 0, 0 );
// Circle
// Imageellipse ($ img, 30,30, 50,50, $ background );
// Elliptic
// Imageellipse ($ img, 30, 30, 50, 30, $ background );
// Draw a straight line
// Imageline ($ img, 0, 0, 400,300, $ background );
// Draw a rectangle
// Imagerectangle ($ img, 50, 20,100, 40, $ background );
// Fill the rectangle
// Imagefilledrectangle ($ img, 50, 20,100, 40, $ background );
// Draw an arc
// Imagearc ($ img, 100,100,150,150,180,270, $ background );
// Draw a fan IMG_ARC_CHORD line to connect the start and end points IMG_ARC_PIE
// Imagefilledarc ($ img, 100,100,150,150,180,270, $ background, IMG_ARC_PIE );
// Copy the image to the canvas
/* $ ScrImg = imagecreatefromgif ('http: // www.baidu.com/img/shouye_b5486898c692066bd2cbaeda86d74448.gif ');
$ ScrImgInfo = getimagesize ('http: // www.baidu.com/img/shouye_b5486898c692066bd2cbaeda86d74448.gif ');
Imagecopy ($ img, $ scrImg, 10, 10, 0, 0, $ scrImgInfo [0], $ scrImgInfo [1]);
*/
// Imagecopy ($ img, $ scrImg, 10, 10, 0, 270,129 );
// Write
// Imagestring ($ img, 5, 20, 20, "hello, world", $ background );
// Write Chinese
$ Str = "PHP painting technology ";
Imagettftext ($ img, 30, 0, 50, 50, $ background, "MSYHBD. TTF", $ str );
// Output the image to the webpage (or save it)
Header ("content-type: image/png ");
Imagepng ($ img );
// Destroy the image (release memory)
Imagedestroy ($ img );
?>
Difference: gif image compression rate is high, but only 256 colors can be displayed, may cause color loss, can...