PHP generates a horizontal percentage Image instance

Source: Internet
Author: User
When you look at the data, you can see that the text is not as good as a number, and the numbers are not separated. in the design of the questionnaire form, the percentage of horizontal columns is displayed to the user. when the user shows the data to the user, the intuitive effect is as follows: the text is not as good as the number, and the number is not separated. in the design of the questionnaire form, the percentage of horizontal columns is displayed to the user. the user can intuitively see which survey or the popularity of a result. The following describes how to implement the technology:
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.
2. the following is a demo file, which is explained in more detail. if you do not understand it, you can only copy the content to the clipboard through ^_^ XML/HTML Code.
  1. // Create a canvas. do not have any output or spaces before the canvas is created. Otherwise, the image cannot be generated.
  2. $ Im = imagecreatetruecolor (100,10 );
    • // $ Cc = imagecolorallocate ($ im, 245,245,245 );
    • // Imagefill ($ im, 0, 0, $ cc );
  3. // Color, in RGB format
  4. $ Red = imagecolorallocate ($ im, 245 );
  5. $ Cc = imagecolorallocate ($ im, 245,245,245 );
  6. // Color
  7. $ Red1 = imagecolorallocate ($ im, 30,144,255 );
  8. $ Red2 = imagecolorallocate ($ im, 220,20, 60 );
  9. $ Red3 = imagecolorallocate ($ im, 0,206,209 );
  10. $ Red4 = imagecolorallocate ($ im, 255,255, 0 );
  11. // 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.
  12. // Circle
  13. // Imageellipse ($ im, 20, 20, 20, $ red );
  14. // Straight line
  15. // Imageline ($ im, 0, 0, 400,300, $ red );
  16. // Rectangle
  17. // Imagerectangle ($ im, $ red );
  18. // Fill the rectangle
  19. Imagefilledrectangle ($ im, 0, 0, 30, 10, $ red );
  20. Imagefilledrectangle ($ im, 30,0, 100,10, $ cc );
  21. // Arc
  22. // Imagearc ($ im, 100,100, 50, 50, 180,270, $ red );
  23. // Slice
  24. // Imagefilledarc ($ im, 100,100, 180,270, $ red, IMG_ARC_PIE );
  25. // Copy the image to the canvas
  26. // 1. load the source image
  27. // $ SrcImage = imagecreatefromgif ("2.GIF ");
  28. // Here we can use a getimagesize ()
  29. // $ SrcImageInfo = getimagesize ("2.GIF ");
  30. // Copy the source image to the target canvas
  31. // Imagecopy ($ im, $ srcImage, 0, 0, 0, $ srcImageInfo [0], $ srcImageInfo [1]);
  32. Header ("content-type: image/png ");
  33. // Generate an image
  34. Imagepng ($ im );
  35. // Release the memory! If this sentence is not added, apache will crash if the traffic is high.
  36. Imagedestory ($ im );
  37. ?>

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.