PHP實(shí)現(xiàn)繪制3D扇形統(tǒng)計(jì)圖及圖片縮放實(shí)例
1、利用php gd庫(kù)的函數(shù)繪制3D扇形統(tǒng)計(jì)圖
<?php header("content-type","text/html;charset=utf-8"); /*扇形統(tǒng)計(jì)圖*/ $image = imagecreatetruecolor(100, 100); /*創(chuàng)建畫布*/ /*設(shè)置畫布需要的顏色*/ $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、對(duì)圖片進(jìn)行縮放
<div> <h4>原圖大小</h4> <img src="1.png" style="border:1px solid red;"> </div> <?php header("content-type","text/html;charset=utf-8"); /* *圖片縮放 *@param string $filename 圖片的url *@param int $width 設(shè)置圖片縮放的最大寬度 *@param int $height 設(shè)置圖片縮放的最大高度 */ 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); } /*調(diào)用函數(shù)*/ thumb('1.png'); ?> <div> <h4>縮放后的大小</h4> <img src="test.png" style="border:1px solid red;"> </div>
效果:
- PHP中創(chuàng)建圖像并繪制文字的例子
- PHP中繪制圖像的一些函數(shù)總結(jié)
- PHP中使用GD庫(kù)繪制折線圖 折線統(tǒng)計(jì)圖的繪制方法
- 利用php繪制餅狀圖的實(shí)現(xiàn)代碼
- php使用Jpgraph繪制復(fù)雜X-Y坐標(biāo)圖的方法
- php GD繪制24小時(shí)柱狀圖
- 如何使用php繪制在圖片上的正余弦曲線
- php使用Jpgraph繪制3D餅狀圖的方法
- php使用GD2繪制幾何圖形示例
- php使用gd2繪制基本圖形示例(直線、圓、正方形)
- 利用php輸出不同的心形圖案
- php實(shí)現(xiàn)的中秋博餅游戲之繪制骰子圖案功能示例
相關(guān)文章
CentOS 7.2 下編譯安裝PHP7.0.10+MySQL5.7.14+Nginx1.10.1的方法詳解(mini版
這篇文章主要介紹了CentOS 7.2 mini版本下編譯安裝PHP7.0.10+MySQL5.7.14+Nginx1.10.1的方法,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-09-09PHP時(shí)間戳 strtotime()使用方法和技巧
php strtotime()解釋如何使用,看了下面的文章就要以學(xué)習(xí)到了。下面還有php文檔函數(shù)解釋。2013-10-10解決PHP curl或file_get_contents下載圖片損壞或無(wú)法打開的問題
今天小編就為大家分享一篇解決PHP curl或file_get_contents下載圖片損壞或無(wú)法打開的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-10-10迪菲-赫爾曼密鑰交換(Diffie–Hellman)算法原理和PHP實(shí)現(xiàn)版
這篇文章主要介紹了迪菲-赫爾曼密鑰交換(Diffie–Hellman)算法原理和PHP實(shí)現(xiàn)版,需要的朋友可以參考下2015-05-05Laravel 微信小程序后端實(shí)現(xiàn)用戶登錄的示例代碼
這篇文章主要介紹了Laravel 微信小程序后端實(shí)現(xiàn)用戶登錄的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-11-11使用PHP+AJAX讓W(xué)ordPress動(dòng)態(tài)加載文章的教程
這篇文章主要介紹了使用PHP+AJAX讓W(xué)ordPress動(dòng)態(tài)加載文章的教程,即不用手動(dòng)刷新瀏覽器頁(yè)面即可讓加載好的文章顯示,需要的朋友可以參考下2015-12-12thinkPHP實(shí)現(xiàn)基于ajax的評(píng)論回復(fù)功能
這篇文章主要介紹了thinkPHP實(shí)現(xiàn)基于ajax的評(píng)論回復(fù)功能,結(jié)合實(shí)例形式分析了thinkPHP實(shí)現(xiàn)ajax評(píng)論回復(fù)所涉及的控制器、視圖、樣式、js使用post進(jìn)行ajax提交、并附帶了相應(yīng)的SQL語(yǔ)句,需要的朋友可以參考下2018-06-06