Analysis of PHP plotting technology _ PHP Tutorial

Source: Internet
Author: User
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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.