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

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

May 25, 2016 pm 04:55 PM

一个PHP中生成横状百分比图片实例代码,有需要了解的朋友可参考参考。
 代码如下 复制代码

//创建画布,在创建前不要有任何输出和空格哦,否则图片生成不了 

$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); 

?> 

注意:1.PHP本身就支持了画图,但必须开启GD库。
打php.ini 文件,找到extension=php_gd2.dll,把前面的分号“;”去掉,重启apache



教程链接:

随意转载~但请保留教程地址★

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 AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

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)