PHP制作3D扇形统计图以及对图片进行缩放操作实例_php实例

WBOY
Release: 2016-06-07 17:16:07
Original
833 people have browsed it

1、利用php gd库的函数绘制3D扇形统计图

header("content-type","text/html;charset=utf-8");<br>/*扇形统计图*/<br>$image = imagecreatetruecolor(100, 100);    /*创建画布*/<br>/*设置画布需要的颜色*/<br>$white = imagecolorallocate($image,0xff,0xff,0xff);<br>$gray = imagecolorallocate($image, 0xc0, 0xc0, 0xc0);<br>$darkgray = imagecolorallocate($image, 0x90, 0x90, 0x90);<br>$navy = imagecolorallocate($image, 0x00, 0x00, 0x80);<br>$darknavy = imagecolorallocate($image, 0x00, 0x00, 0x50);<br>$red = imagecolorallocate($image, 0xff, 0x00, 0x00);<br>$darkred = imagecolorallocate($image, 0x90, 0x00, 0x00);<br>/*填充背景色*/<br>imagefill($image, 0, 0, $white);<br>/*3D制作*/<br>for($i = 60; $i > 50; $i--)<br>{<br>imagefilledarc($image, 50, $i, 100, 50, -160, 40, $darknavy, IMG_ARC_PIE);<br>imagefilledarc($image, 50, $i, 100, 50, 40, 75, $darkgray, IMG_ARC_PIE);<br>imagefilledarc($image, 50, $i, 100, 50, 75, 200, $darkred, IMG_ARC_PIE);<br>}<br>/*画椭圆弧并填充*/<br>imagefilledarc($image, 50, 50, 100, 50, -160, 40, $darknavy, IMG_ARC_PIE);<br>imagefilledarc($image, 50, 50, 100, 50, 40, 75, $darkgray, IMG_ARC_PIE);<br>imagefilledarc($image, 50, 50, 100, 50, 75, 200, $darkred, IMG_ARC_PIE);<br>/*画字符串*/<br>imagestring($image, 3, 15, 55, "30%", $white);<br>imagestring($image, 3, 45, 35, "60%", $white);<br>imagestring($image, 3, 60, 60, "10%", $white);<br>/*输出图像*/<br>header("content-type:image/png");<br>imagepng($image);<br>/*释放资源*/<br>imagedestroy($image);<br>?>
Copy after login

效果:

2、对图片进行缩放

<div>
<br><h4>原图大小</h4>
<br><img  src="1.png" alt="PHP制作3D扇形统计图以及对图片进行缩放操作实例_php实例" ><br>
</div><br>header("content-type","text/html;charset=utf-8");<br>/*<br>*图片缩放<br>*@param string $filename   图片的url<br>*@param int    $width      设置图片缩放的最大宽度<br>*@param int    $height     设置图片缩放的最大高度<br>*/<br>function thumb($filename,$width=130,$height=130)<br>{<br>/*获取原图的大小*/<br>list($width_orig,$height_orig) = getimagesize($filename);<br>/*根据参数$width和$height,换算出等比例的高度和宽度*/<br>if($width && ($width_orig {<br>$width = ($height / $height_orig) * $width_orig;<br>}<br>else<br>{<br>$height = ($width / $width_orig) * $height_orig;<br>}<br>/*以新的大小创建画布*/<br>$image_p = imagecreatetruecolor($width, $height);<br>/*获取图像资源*/<br>$image = imagecreatefrompng($filename);<br>/*使用imagecopyresampled缩放*/<br>imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);<br>/*保存缩放后的图片和命名*/<br>imagepng($image_p,'test.png');<br>/*释放资源*/<br>imagedestroy($image_p);<br>imagedestroy($image);<br>}<br>/*调用函数*/<br>thumb('1.png');<br>?><br><div>
<br><h4>缩放后的大小</h4>
<br><img  src="test.png" alt="PHP制作3D扇形统计图以及对图片进行缩放操作实例_php实例" ><br>
</div>
Copy after login

效果:

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template