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 相关文章推荐
PHP新手上路(十二)
Oct 09 PHP
PHP5 操作MySQL数据库基础代码
Sep 29 PHP
基于Zend的Captcha机制的应用
May 02 PHP
优化PHP代码技巧的小结
Jun 02 PHP
解析获取优酷视频真实下载地址的PHP源代码
Jun 26 PHP
Yii框架form表单用法实例
Dec 04 PHP
yii2.0之GridView自定义按钮和链接用法
Dec 15 PHP
PHP strcmp()和strcasecmp()的区别实例
Nov 05 PHP
Laravel 实现数据软删除功能
Aug 21 PHP
PHP的介绍以及优势详细分析
Sep 05 PHP
php进行md5加密简单实例方法
Sep 19 PHP
Laravel 简单实现Ajax滚动加载示例
Oct 22 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删除数组元素示例分享
2014/02/17 PHP
Drupal读取Excel并导入数据库实例
2014/03/02 PHP
浅谈PHP正则中的捕获组与非捕获组
2016/07/18 PHP
php脚本守护进程原理与实现方法详解
2017/07/20 PHP
模仿jQuery each函数的链式调用
2009/07/22 Javascript
js apply/call/caller/callee/bind使用方法与区别分析
2009/10/28 Javascript
Javascript异步表单提交,图片上传,兼容异步模拟ajax技术
2010/05/10 Javascript
js点击页面其它地方将某个显示的DIV隐藏
2012/07/12 Javascript
js实现touch移动触屏滑动事件
2015/04/17 Javascript
Vue ElementUI之Form表单验证遇到的问题
2017/08/21 Javascript
angularjs实现柱状图动态加载的示例
2017/12/11 Javascript
vue.js 实现图片本地预览 裁剪 压缩 上传功能
2018/03/01 Javascript
webpack优化的深入理解
2018/12/10 Javascript
小程序开发踩坑:页面窗口定位(相对于浏览器定位)(推荐)
2019/04/25 Javascript
Vue 列表上下过渡效果的实例代码
2019/06/25 Javascript
微信小程序开发(一):服务器获取数据列表渲染操作示例
2020/06/01 Javascript
微信小程序实现购物车功能
2020/11/18 Javascript
python读取csv文件示例(python操作csv)
2014/03/11 Python
virtualenv实现多个版本Python共存
2017/08/21 Python
基于MTCNN/TensorFlow实现人脸检测
2018/05/24 Python
Python3.5字符串常用操作实例详解
2019/05/01 Python
Python之Class&amp;Object用法详解
2019/12/25 Python
python如何爬取动态网站
2020/09/09 Python
纯CSS3实现3D旋转书本效果
2016/03/21 HTML / CSS
卡骆驰英国官网:Crocs英国
2019/08/22 全球购物
质检员的岗位职责
2013/11/15 职场文书
金融专业个人求职信范文
2013/11/28 职场文书
开朗女孩的自我评价
2014/02/10 职场文书
公益广告语集锦
2014/03/13 职场文书
专业技术职务聘任证明
2015/03/02 职场文书
大学生就业推荐表自我评价
2015/03/02 职场文书
暑假打工感想
2015/08/07 职场文书
2016新年晚会开场白
2015/12/03 职场文书
2016优秀护士求职自荐信
2016/01/28 职场文书
python爬取企查查企业信息之selenium自动模拟登录企查查
2021/04/08 Python
MySQL中EXPLAIN语句及用法
2022/05/20 MySQL