Generate a horizontal percentage Image instance in PHP

Source: Internet
Author: User
A php instance code that generates a horizontal percentage Image. For more information, see. The code is as follows: Copy the code? Php creates a canvas. do not create a canvas before it is created...

A php instance code that generates a horizontal percentage Image. For more information, see.

The code is as follows:

// Create a canvas. do not have any output or spaces before the canvas is created. Otherwise, the image cannot be generated.

$ Im = imagecreatetruecolor (100,10 );
// $ Cc = imagecolorallocate ($ im, 245,245,245 );

// Imagefill ($ im, 0, 0, $ cc );

// Color, in RGB format

$ Red = imagecolorallocate ($ im, 245 );

$ Cc = imagecolorallocate ($ im, 245,245,245 );

// Color

$ Red1 = imagecolorallocate ($ im, 30,144,255 );

$ Red2 = imagecolorallocate ($ im, 220,20, 60 );

$ Red3 = imagecolorallocate ($ im, 0,206,209 );

$ Red4 = imagecolorallocate ($ im, 255,255, 0 );

// The color of the filled rectangle can be customized. The color defined above is just a test example here. the length ratio can be controlled based on the project's dynamic data.

// Circle

// Imageellipse ($ im, 20, 20, 20, $ red );

// Straight line

// Imageline ($ im, 0, 0, 400,300, $ red );

// Rectangle

// Imagerectangle ($ im, $ red );

// Fill the rectangle

Imagefilledrectangle ($ im, 0, 0, 30, 10, $ red );

Imagefilledrectangle ($ im, 30,0, 100,10, $ cc );

// Arc

// Imagearc ($ im, 100,100, 50, 50, 180,270, $ red );

// Slice

// Imagefilledarc ($ im, 100,100, 180,270, $ red, IMG_ARC_PIE );

// Copy the image to the canvas

// 1. load the source image

// $ SrcImage = imagecreatefromgif ("2.GIF ");

// Here we can use a getimagesize ()

// $ SrcImageInfo = getimagesize ("2.GIF ");

// Copy the source image to the target canvas

// Imagecopy ($ im, $ srcImage, 0, 0, 0, $ srcImageInfo [0], $ srcImageInfo [1]);

Header ("content-type: image/png ");

// Generate an image

Imagepng ($ im );

// Release the memory! If this sentence is not added, apache will crash if the traffic is high.

Imagedestory ($ im );

?>

Note: 1. PHP supports drawing, but the GD library must be enabled.
In the php. ini file, find extension = php_gd2.dll, remove the semicolon ";", and restart apache.



Tutorial link:

Reprint at will ~ However, please keep the tutorial address★

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.