PHP生成横状百分比图片实例
给用户看数据的时候,直观效果上:文字不如数字,数字不如图片.在调查表的设计上采用横柱百分比图片形式展示给用户,用户很直观的看出哪个调查或某个结果的热门程度。下面是分享如何实现技术:
1.PHP本身就支持了画图,但必须开启GD库。
打php.ini 文件,找到extension=php_gd2.dll,把前面的分号“;”去掉,重启apache
2.下面是一个demo文件,解释说的比较详细了,再不懂只能百度了^_^
XML/HTML Code
- //创建画布,在创建前不要有任何输出和空格哦,否则图片生成不了
-
$im=imagecreatetruecolor(100,10);
- //$cc=imagecolorallocate($im,245,245,245);
- //imagefill($im,0,0,$cc);
- //着色的颜色,采用的是RGB的格式
- $red=imagecolorallocate($im,0,0,245);
- $cc=imagecolorallocate($im,245,245,245);
- //颜色
- $red1 = imagecolorallocate($im,30,144,255);
- $red2 = imagecolorallocate($im,220,20,60);
- $red3 = imagecolorallocate($im,0,206,209);
- $red4 = imagecolorallocate($im,255,255,0);
- //填充矩形颜色可以自定义填充的颜色,上面定义的颜色在这里我只是做测试例子,至于长度比例大小可以根据项目动态数据来控制
- //圆
- //imageellipse($im,20,20,20,20,$red);
- //直线
- //imageline($im,0,0,400,300,$red);
- //矩形
- //imagerectangle($im,0,0,100,10,$red);
- //填充矩形
- imagefilledrectangle($im,0,0,30,10,$red);
- imagefilledrectangle($im,30,0,100,10,$cc);
- //弧线
- //imagearc($im,100,100,50,50,180,270,$red);
- //扇形
- //imagefilledarc($im,100,100,80,50,180,270,$red,IMG_ARC_PIE);
- //拷贝图片到画布
- //1.加载源图片
- //$srcImage=imagecreatefromgif("2.GIF");
- //这里我们可以使用一个getimagesize()
- //$srcImageInfo=getimagesize("2.GIF");
- //拷贝源图片到目标画布
- //imagecopy($im,$srcImage,0,0,0,0,$srcImageInfo[0],$srcImageInfo[1]);
- header("content-type: image/png");
- //生成图片
- imagepng($im);
- //释放内存,亲,注意咯!如果不加这句,访问量大的话apache会爆掉的哦
- imagedestory($im);
- ?>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Building a Hadoop Distributed File System (HDFS) on a CentOS system requires multiple steps. This article provides a brief configuration guide. 1. Prepare to install JDK in the early stage: Install JavaDevelopmentKit (JDK) on all nodes, and the version must be compatible with Hadoop. The installation package can be downloaded from the Oracle official website. Environment variable configuration: Edit /etc/profile file, set Java and Hadoop environment variables, so that the system can find the installation path of JDK and Hadoop. 2. Security configuration: SSH password-free login to generate SSH key: Use the ssh-keygen command on each node

Enable Redis slow query logs on CentOS system to improve performance diagnostic efficiency. The following steps will guide you through the configuration: Step 1: Locate and edit the Redis configuration file First, find the Redis configuration file, usually located in /etc/redis/redis.conf. Open the configuration file with the following command: sudovi/etc/redis/redis.conf Step 2: Adjust the slow query log parameters in the configuration file, find and modify the following parameters: #slow query threshold (ms)slowlog-log-slower-than10000#Maximum number of entries for slow query log slowlog-max-len

How does the Redis caching solution realize the requirements of product ranking list? During the development process, we often need to deal with the requirements of rankings, such as displaying a...

VprocesserazrabotkiveB-enclosed, Мнепришлостольностьсясзадачейтерациигооглапидляпапакробоглесхетсigootrive. LEAVALLYSUMBALLANCEFRIABLANCEFAUMDOPTOMATIFICATION, ČtookazaLovnetakProsto, Kakaožidal.Posenesko

In SpringBoot, use Redis to cache OAuth2Authorization object. In SpringBoot application, use SpringSecurityOAuth2AuthorizationServer...

When configuring Hadoop Distributed File System (HDFS) on CentOS, the following key configuration files need to be modified: core-site.xml: fs.defaultFS: Specifies the default file system address of HDFS, such as hdfs://localhost:9000. hadoop.tmp.dir: Specifies the storage directory for Hadoop temporary files. hadoop.proxyuser.root.hosts and hadoop.proxyuser.ro

Troubleshooting HDFS configuration errors under CentOS Systems This article is intended to help you solve problems encountered when configuring HDFS in CentOS systems. Please follow the following steps to troubleshoot: Java environment verification: Confirm that the JAVA_HOME environment variable is set correctly. Add the following in the /etc/profile or ~/.bashrc file: exportJAVA_HOME=/path/to/your/javaexportPATH=$JAVA_HOME/bin: $PATHExecute source/etc/profile or source~/.bashrc to make the configuration take effect. Hadoop

When installing and configuring GitLab on a CentOS system, the choice of database is crucial. GitLab is compatible with multiple databases, but PostgreSQL and MySQL (or MariaDB) are most commonly used. This article analyzes database selection factors and provides detailed installation and configuration steps. Database Selection Guide When choosing a database, you need to consider the following factors: PostgreSQL: GitLab's default database is powerful, has high scalability, supports complex queries and transaction processing, and is suitable for large application scenarios. MySQL/MariaDB: a popular relational database widely used in Web applications, with stable and reliable performance. MongoDB:NoSQL database, specializes in
