PHP制作3D扇形統(tǒng)計圖以及對圖片進行縮放操作實例
更新時間:2014年10月23日 10:17:13 投稿:hebedich
這篇文章主要介紹了PHP制作3D扇形統(tǒng)計圖以及對圖片進行縮放操作實例,需要的朋友可以參考下
1、利用php gd庫的函數(shù)繪制3D扇形統(tǒng)計圖
<?php
header("content-type","text/html;charset=utf-8");
/*扇形統(tǒng)計圖*/
$image = imagecreatetruecolor(100, 100); /*創(chuàng)建畫布*/
/*設置畫布需要的顏色*/
$white = imagecolorallocate($image,0xff,0xff,0xff);
$gray = imagecolorallocate($image, 0xc0, 0xc0, 0xc0);
$darkgray = imagecolorallocate($image, 0x90, 0x90, 0x90);
$navy = imagecolorallocate($image, 0x00, 0x00, 0x80);
$darknavy = imagecolorallocate($image, 0x00, 0x00, 0x50);
$red = imagecolorallocate($image, 0xff, 0x00, 0x00);
$darkred = imagecolorallocate($image, 0x90, 0x00, 0x00);
/*填充背景色*/
imagefill($image, 0, 0, $white);
/*3D制作*/
for($i = 60; $i > 50; $i--)
{
imagefilledarc($image, 50, $i, 100, 50, -160, 40, $darknavy, IMG_ARC_PIE);
imagefilledarc($image, 50, $i, 100, 50, 40, 75, $darkgray, IMG_ARC_PIE);
imagefilledarc($image, 50, $i, 100, 50, 75, 200, $darkred, IMG_ARC_PIE);
}
/*畫橢圓弧并填充*/
imagefilledarc($image, 50, 50, 100, 50, -160, 40, $darknavy, IMG_ARC_PIE);
imagefilledarc($image, 50, 50, 100, 50, 40, 75, $darkgray, IMG_ARC_PIE);
imagefilledarc($image, 50, 50, 100, 50, 75, 200, $darkred, IMG_ARC_PIE);
/*畫字符串*/
imagestring($image, 3, 15, 55, "30%", $white);
imagestring($image, 3, 45, 35, "60%", $white);
imagestring($image, 3, 60, 60, "10%", $white);
/*輸出圖像*/
header("content-type:image/png");
imagepng($image);
/*釋放資源*/
imagedestroy($image);
?>
效果:

2、對圖片進行縮放
<div>
<h4>原圖大小</h4>
<img src="1.png">
</div>
<?php
header("content-type","text/html;charset=utf-8");
/*
*圖片縮放
*@param string $filename 圖片的url
*@param int $width 設置圖片縮放的最大寬度
*@param int $height 設置圖片縮放的最大高度
*/
function thumb($filename,$width=130,$height=130)
{
/*獲取原圖的大小*/
list($width_orig,$height_orig) = getimagesize($filename);
/*根據(jù)參數(shù)$width和$height,換算出等比例的高度和寬度*/
if($width && ($width_orig < $height_orig))
{
$width = ($height / $height_orig) * $width_orig;
}
else
{
$height = ($width / $width_orig) * $height_orig;
}
/*以新的大小創(chuàng)建畫布*/
$image_p = imagecreatetruecolor($width, $height);
/*獲取圖像資源*/
$image = imagecreatefrompng($filename);
/*使用imagecopyresampled縮放*/
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
/*保存縮放后的圖片和命名*/
imagepng($image_p,'test.png');
/*釋放資源*/
imagedestroy($image_p);
imagedestroy($image);
}
/*調用函數(shù)*/
thumb('1.png');
?>
<div>
<h4>縮放后的大小</h4>
<img src="test.png">
</div>
效果:

相關文章
PHP中字符與字節(jié)的區(qū)別及字符串與字節(jié)轉換示例
在php中字符是可使用多種不同字符方案或代碼頁來表示的抽象實體。字節(jié)是通過網(wǎng)絡傳輸信息(或在硬盤或內存中存儲信息)的單位。本文還通過實例給大家介紹了php中字符串與字節(jié)轉換示例,感興趣的朋友一起看看吧2016-10-10
Laravel5.1 框架模型工廠ModelFactory用法實例分析
這篇文章主要介紹了Laravel5.1 框架模型工廠ModelFactory用法,結合實例形式分析了laravel5.1框架模型工廠ModelFactory基本功能、定義與使用方法,需要的朋友可以參考下2020-01-01
ecshop適應在PHP7的修改方法解決報錯的實現(xiàn)
下面小編就為大家?guī)硪黄猠cshop適應在PHP7的修改方法解決報錯的實現(xiàn)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-11-11
Thinkphp5.0 框架實現(xiàn)控制器向視圖view賦值及視圖view取值操作示例
這篇文章主要介紹了Thinkphp5.0 框架實現(xiàn)控制器向視圖view賦值及視圖view取值操作,結合實例形式分析了thinkPHP控制器向視圖傳值及從視圖取值相關操作技巧,需要的朋友可以參考下2019-10-10

