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 相关文章推荐
ASP和PHP都是可以删除自身的
Apr 09 PHP
攻克CakePHP系列三 表单数据增删改
Oct 22 PHP
PHP写的获取各搜索蜘蛛爬行记录代码
Aug 21 PHP
php中用memcached实现页面防刷新功能
Aug 19 PHP
php找出指定范围内回文数且平方根也是回文数的方法
Mar 23 PHP
PHP使用缓存即时输出内容(output buffering)的方法
Aug 03 PHP
php支付宝在线支付接口开发教程
Sep 19 PHP
PHP页面输出搜索后跳转下一页的处理方法
Sep 30 PHP
PHP异常处理定义与使用方法分析
Jul 25 PHP
PHP排序算法之堆排序(Heap Sort)实例详解
Apr 21 PHP
使用PHP+Redis实现延迟任务,实现自动取消订单功能
Nov 21 PHP
thinkphp5 路由分发原理
Mar 18 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
PHP通过正则表达式下载图片到本地的实现代码
2011/09/19 PHP
yii2中结合gridview如何使用modal弹窗实例代码详解
2016/06/12 PHP
PHP中常用的魔术方法
2017/04/28 PHP
javascript多种数据类型表格排序代码分析
2010/09/11 Javascript
使用javascipt---实现二分查找法
2013/04/10 Javascript
node.js中的fs.statSync方法使用说明
2014/12/16 Javascript
深入理解JavaScript系列(41):设计模式之模板方法详解
2015/03/04 Javascript
原生JavaScript实现异步多文件上传
2015/12/02 Javascript
jquery获取复选框的值的简单实例
2016/05/26 Javascript
Node.js Express 框架 POST方法详解
2017/01/23 Javascript
进阶之初探nodeJS
2017/01/24 NodeJs
javascript 初学教程及五子棋小程序的简单实现
2017/07/04 Javascript
JavaScript实现的可变动态数字键盘控件方式实例代码
2017/07/15 Javascript
vue底部加载更多的实例代码
2018/06/29 Javascript
vue 中Virtual Dom被创建的方法
2019/04/15 Javascript
JavaScript怎样在删除前添加确认弹出框?
2019/05/27 Javascript
vue实现搜索功能
2019/05/28 Javascript
用Python编写一个基于终端的实现翻译的脚本
2015/04/24 Python
解决python nohup linux 后台运行输出的问题
2018/05/11 Python
Django 创建/删除用户的示例代码
2019/07/24 Python
Python的几种主动结束程序方式
2019/11/22 Python
Python如何访问字符串中的值
2020/02/09 Python
django admin 添加自定义链接方式
2020/03/11 Python
python对接ihuyi实现短信验证码发送
2020/05/10 Python
Python sorted对list和dict排序
2020/06/09 Python
浅析关于Keras的安装(pycharm)和初步理解
2020/10/23 Python
python爬虫scrapy基于CrawlSpider类的全站数据爬取示例解析
2021/02/20 Python
CSS3实现全景图特效示例代码
2018/03/26 HTML / CSS
中国跨境电商:Tomtop
2017/03/16 全球购物
中专毕业生求职简历的自我评价
2013/10/21 职场文书
数控专业毕业生自荐信范文
2014/03/04 职场文书
2014最新预备党员思想汇报范文:中国梦,我的梦
2014/10/25 职场文书
工伤私了协议书范本
2014/11/24 职场文书
2015年社区中秋节活动总结
2015/03/23 职场文书
关于法制教育的宣传语
2015/07/13 职场文书
解决python绘图使用subplots出现标题重叠的问题
2021/04/30 Python