Home > Backend Development > PHP Tutorial > Examples of making 3D fan charts and zooming pictures with PHP, _PHP tutorial

Examples of making 3D fan charts and zooming pictures with PHP, _PHP tutorial

WBOY
Release: 2016-07-13 10:16:22
Original
1123 people have browsed it

Examples of making 3D fan charts and zooming pictures with PHP,

1. Use the function of php gd library to draw 3D sector statistical chart

<&#63;php<br />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

Effect:

2. Zoom in on the image

<div><br><h4>原图大小</h4><br><img src="1.png"><br></div><br><&#63;php<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 < $height_orig))<br />{<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 />&#63;><br><div><br><h4>缩放后的大小</h4><br><img src="test.png"><br></div>
Copy after login

Effect:

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/898290.htmlTechArticleExamples of making 3D fan charts and scaling pictures with PHP, 1. Use the functions of the php gd library to draw 3D Fan chart php header("content-type","text/html;charset=utf-8"); /*Sector...
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