PHP实现绘制3D扇形统计图及图片缩放实例


Posted in PHP onOctober 01, 2014

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

<?php
  header("content-type","text/html;charset=utf-8");
  /*扇形统计图*/
  $image = imagecreatetruecolor(100, 100);  /*创建画布*/
  
  /*设置画布需要的颜色*/
  $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);
  ?>

效果:

PHP实现绘制3D扇形统计图及图片缩放实例

2、对图片进行缩放

<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   设置图片缩放的最大宽度
  *@param int  $height   设置图片缩放的最大高度
  */
  function thumb($filename,$width=130,$height=130)
  {
    /*获取原图的大小*/
    list($width_orig,$height_orig) = getimagesize($filename);
 
    /*根据参数$width和$height,换算出等比例的高度和宽度*/
    if($width && ($width_orig < $height_orig))
    {
      $width = ($height / $height_orig) * $width_orig;
    }
    else
    {
      $height = ($width / $width_orig) * $height_orig;
    }
 
    /*以新的大小创建画布*/
    $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);
  }
  /*调用函数*/
  thumb('1.png');
  ?>
  <div>
    <h4>缩放后的大小</h4>
    <img src="test.png" style="border:1px solid red;">
  </div>

效果:

PHP实现绘制3D扇形统计图及图片缩放实例

PHP 相关文章推荐
Discuz!下Memcache缓存实现方法
May 28 PHP
PHP用SAX解析XML的实现代码与问题分析
Aug 22 PHP
PHP基础学习之流程控制的实现分析
Apr 28 PHP
php中\r \r\n \t的区别示例介绍
Feb 08 PHP
php实现上传图片生成缩略图示例
Apr 13 PHP
通过dbi使用perl连接mysql数据库的方法
Apr 16 PHP
php实现读取超大文件的方法
Jul 28 PHP
非常经典的PHP文件上传类分享
May 15 PHP
Yii2主题(Theme)用法详解
Jul 23 PHP
基于php(Thinkphp)+jquery 实现ajax多选反选不选删除数据功能
Feb 24 PHP
PHP实现二维数组中的查找算法小结
Jun 09 PHP
Laravel开启跨域请求的方法
Oct 13 PHP
PHP的switch判断语句的“高级”用法详解
Oct 01 #PHP
php中文字符串截取方法实例总结
Sep 30 #PHP
php出现web系统多域名登录失败的解决方法
Sep 30 #PHP
php中运用http调用的GET和POST方法示例
Sep 29 #PHP
PHP中魔术变量__METHOD__与__FUNCTION__的区别
Sep 29 #PHP
PHP中echo,print_r与var_dump区别分析
Sep 29 #PHP
PHP5.3安装Zend Guard Loader图文教程
Sep 29 #PHP
You might like
将OICQ数据转成MYSQL数据
2006/10/09 PHP
php curl登陆qq后获取用户信息时证书错误
2015/02/03 PHP
yii2.0整合阿里云oss上传单个文件的示例
2017/09/19 PHP
JSON 学习之完全手册 图文
2007/05/29 Javascript
jquery中的$(document).ready()与window.onload的区别
2009/11/18 Javascript
Jquery实现点击切换图片并隐藏显示内容(2种方法实现)
2013/04/11 Javascript
JQuery获取样式中的background-color颜色值的问题
2013/08/20 Javascript
javascript组合使用构造函数模式和原型模式实例
2015/06/04 Javascript
简述AngularJS相关的一些编程思想
2015/06/23 Javascript
JavaScript检测字符串中是否含有html标签实现方法
2015/07/01 Javascript
浅谈jquery.fn.extend与jquery.extend区别
2015/07/13 Javascript
灵活的理解JavaScript中的this指向
2016/02/25 Javascript
jQuery实现可移动选项的左右下拉列表示例
2016/12/26 Javascript
浅谈JS验证表单文本域输入空格的问题
2017/02/14 Javascript
Web开发使用Angular实现用户密码强度判别的方法
2017/09/27 Javascript
vue使用v-for实现hover点击效果
2018/09/29 Javascript
nodejs异步编程基础之回调函数用法分析
2018/12/26 NodeJs
详解关于Vuex的action传入多个参数的问题
2019/02/22 Javascript
HTML元素拖拽功能实现的完整实例
2020/12/04 Javascript
Python实现大文件排序的方法
2015/07/10 Python
python和shell获取文本内容的方法
2018/06/05 Python
python远程连接服务器MySQL数据库
2018/07/02 Python
Python 实现域名解析为ip的方法
2019/02/14 Python
利用Python查看微信共同好友功能的实现代码
2019/04/24 Python
Python: 传递列表副本方式
2019/12/19 Python
python 读取yaml文件的两种方法(在unittest中使用)
2020/12/01 Python
css3实现书本翻页效果的示例代码
2021/03/08 HTML / CSS
Chi Chi London官网:购买连衣裙和礼服
2020/10/25 全球购物
初中生期末评语大全
2014/04/24 职场文书
生产车间标语
2014/06/11 职场文书
中国梦团日活动总结
2014/07/07 职场文书
干部对照检查材料范文
2014/08/26 职场文书
民主评议党员自我评议范文2014
2014/09/26 职场文书
2015年七一建党节慰问信
2015/03/23 职场文书
工程技术负责人岗位职责
2015/04/13 职场文书
单位介绍信格式范文
2015/05/04 职场文书