Home php教程 php手册 PHP生成横状百分比图片实例

PHP生成横状百分比图片实例

Jun 21, 2016 am 08:50 AM
nbsp quot red

 给用户看数据的时候,直观效果上:文字不如数字,数字不如图片.在调查表的设计上采用横柱百分比图片形式展示给用户,用户很直观的看出哪个调查或某个结果的热门程度。下面是分享如何实现技术:
1.PHP本身就支持了画图,但必须开启GD库。
打php.ini 文件,找到extension=php_gd2.dll,把前面的分号“;”去掉,重启apache
2.下面是一个demo文件,解释说的比较详细了,再不懂只能百度了^_^

 

XML/HTML Code

  1.     //创建画布,在创建前不要有任何输出和空格哦,否则图片生成不了  
  2.  $im=imagecreatetruecolor(100,10);
    • //$cc=imagecolorallocate($im,245,245,245);
    • //imagefill($im,0,0,$cc);
      
  3.  //着色的颜色,采用的是RGB的格式  
  4.  $red=imagecolorallocate($im,0,0,245);   
  5.  $cc=imagecolorallocate($im,245,245,245);  
  6.  //颜色  
  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.  //填充矩形颜色可以自定义填充的颜色,上面定义的颜色在这里我只是做测试例子,至于长度比例大小可以根据项目动态数据来控制  
  12. //圆  
  13. //imageellipse($im,20,20,20,20,$red);  
  14. //直线  
  15. //imageline($im,0,0,400,300,$red);  
  16. //矩形  
  17. //imagerectangle($im,0,0,100,10,$red);  
  18. //填充矩形  
  19. imagefilledrectangle($im,0,0,30,10,$red);  
  20. imagefilledrectangle($im,30,0,100,10,$cc);  
  21. //弧线  
  22. //imagearc($im,100,100,50,50,180,270,$red);  
  23. //扇形  
  24. //imagefilledarc($im,100,100,80,50,180,270,$red,IMG_ARC_PIE);  
  25. //拷贝图片到画布  
  26. //1.加载源图片  
  27. //$srcImage=imagecreatefromgif("2.GIF");  
  28. //这里我们可以使用一个getimagesize()  
  29. //$srcImageInfo=getimagesize("2.GIF");  
  30. //拷贝源图片到目标画布  
  31. //imagecopy($im,$srcImage,0,0,0,0,$srcImageInfo[0],$srcImageInfo[1]);  
  32.  header("content-type: image/png");  
  33.  //生成图片  
  34.  imagepng($im);  
  35.  //释放内存,亲,注意咯!如果不加这句,访问量大的话apache会爆掉的哦  
  36.  imagedestory($im);  
  37. ?>  



Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Solution: Your organization requires you to change your PIN Solution: Your organization requires you to change your PIN Oct 04, 2023 pm 05:45 PM

Solution: Your organization requires you to change your PIN

How to adjust window border settings on Windows 11: Change color and size How to adjust window border settings on Windows 11: Change color and size Sep 22, 2023 am 11:37 AM

How to adjust window border settings on Windows 11: Change color and size

How to change title bar color on Windows 11? How to change title bar color on Windows 11? Sep 14, 2023 pm 03:33 PM

How to change title bar color on Windows 11?

How to enable or disable taskbar thumbnail previews on Windows 11 How to enable or disable taskbar thumbnail previews on Windows 11 Sep 15, 2023 pm 03:57 PM

How to enable or disable taskbar thumbnail previews on Windows 11

OOBELANGUAGE Error Problems in Windows 11/10 Repair OOBELANGUAGE Error Problems in Windows 11/10 Repair Jul 16, 2023 pm 03:29 PM

OOBELANGUAGE Error Problems in Windows 11/10 Repair

Display scaling guide on Windows 11 Display scaling guide on Windows 11 Sep 19, 2023 pm 06:45 PM

Display scaling guide on Windows 11

10 Ways to Adjust Brightness on Windows 11 10 Ways to Adjust Brightness on Windows 11 Dec 18, 2023 pm 02:21 PM

10 Ways to Adjust Brightness on Windows 11

How to turn off private browsing authentication for iPhone in Safari? How to turn off private browsing authentication for iPhone in Safari? Nov 29, 2023 pm 11:21 PM

How to turn off private browsing authentication for iPhone in Safari?

See all articles