php生成圆角图片的方法


Posted in PHP onApril 07, 2015

本文实例讲述了php生成圆角图片的方法。分享给大家供大家参考。具体如下:

<?php

$image_file = $_GET['src'];

$corner_radius = isset($_GET['radius']) ? $_GET['radius'] : 20; // The default corner radius is set to 20px

$topleft = (isset($_GET['topleft']) and $_GET['topleft'] == "no") ? false : true; // Top-left rounded corner is shown by default

$bottomleft = (isset($_GET['bottomleft']) and $_GET['bottomleft'] == "no") ? false : true; // Bottom-left rounded corner is shown by default

$bottomright = (isset($_GET['bottomright']) and $_GET['bottomright'] == "no") ? false : true; // Bottom-right rounded corner is shown by default

$topright = (isset($_GET['topright']) and $_GET['topright'] == "no") ? false : true; // Top-right rounded corner is shown by default

$imagetype=strtolower($_GET['imagetype']);

$backcolor=$_GET['backcolor'];

$endsize=$corner_radius;

$startsize=$endsize*3-1;

$arcsize=$startsize*2+1;

if (($imagetype=='jpeg') or ($imagetype=='jpg')) {

$image = imagecreatefromjpeg($image_file);

} else {

if (($imagetype=='GIF') or ($imagetype=='gif')) {

$image = imagecreatefromgif($image_file);

} else {

$image = imagecreatefrompng($image_file);

}

}

$size = getimagesize($image_file);

// Top-left corner

$background = imagecreatetruecolor($size[0],$size[1]);

imagecopymerge($background,$image,0,0,0,0,$size[0],$size[1],100);

$startx=$size[0]*2-1;

$starty=$size[1]*2-1;

$im_temp = imagecreatetruecolor($startx,$starty);

imagecopyresampled($im_temp, $background, 0, 0, 0, 0, $startx, $starty, $size[0], $size[1]);

$bg = imagecolorallocate($im_temp, hexdec(substr($backcolor,0,2)),hexdec(substr($backcolor,2,2)),hexdec(substr($backcolor,4,2)));

$fg = imagecolorallocate($im_temp, hexdec(substr($forecolor,0,2)),hexdec(substr($forecolor,2,2)),hexdec(substr($forecolor,4,2)));

if ($topleft == true) {

imagearc($im_temp, $startsize, $startsize, $arcsize, $arcsize, 180,270,$bg);

imagefilltoborder($im_temp,0,0,$bg,$bg);

}

// Bottom-left corner

if ($bottomleft == true) {

imagearc($im_temp,$startsize,$starty-$startsize,$arcsize,$arcsize,90,180,$bg);

imagefilltoborder($im_temp,0,$starty,$bg,$bg);

}

// Bottom-right corner

if ($bottomright == true) {

imagearc($im_temp, $startx-$startsize, $starty-$startsize,$arcsize, $arcsize, 0,90,$bg);

imagefilltoborder($im_temp,$startx,$starty,$bg,$bg);

}

// Top-right corner

if ($topright == true) {

imagearc($im_temp, $startx-$startsize, $startsize,$arcsize, $arcsize, 270,360,$bg);

imagefilltoborder($im_temp,$startx,0,$bg,$bg);

}

$newimage = imagecreatetruecolor($size[0],$size[1]);

imagecopyresampled($image,$im_temp,0,0,0,0,$size[0],$size[1],$startx,$starty);

// Output final image

header("Content-type: image/png");

imagepng($image);

imagedestroy($image);

imagedestroy($background);

imagedestroy($im_temp);

?>

希望本文所述对大家的php程序设计有所帮助。

PHP 相关文章推荐
PHP文件上传原理简单分析
May 29 PHP
解析zend Framework如何自动加载类
Jun 28 PHP
php根据isbn书号查询amazon网站上的图书信息的示例
Feb 13 PHP
php中把美国时间转为北京时间的自定义函数分享
Jul 28 PHP
php常用字符串比较函数实例汇总
Nov 24 PHP
php简单计算页面加载时间的方法
Jun 19 PHP
使用图灵api创建微信聊天机器人
Jul 23 PHP
PHP封装CURL扩展类实例
Jul 28 PHP
PHP制作用户注册系统
Oct 23 PHP
php+MySql实现登录系统与输出浏览者信息功能
Jul 01 PHP
PHP实现Huffman编码/解码的示例代码
Apr 20 PHP
CentOS7.0下安装PHP5.6.30服务的教程详解
Sep 29 PHP
php按单词截取字符串的方法
Apr 07 #PHP
php生成zip文件类实例
Apr 07 #PHP
php生成图片缩略图的方法
Apr 07 #PHP
Nginx下配置codeigniter框架方法
Apr 07 #PHP
Windows下Apache + PHP SESSION丢失的解决过程全纪录
Apr 07 #PHP
php修改文件上传限制方法汇总
Apr 07 #PHP
windows下安装php的memcache模块的方法
Apr 07 #PHP
You might like
PHP实现时间轴函数代码
2011/10/08 PHP
php将金额数字转化为中文大写
2015/07/09 PHP
详解PHP实现定时任务的五种方法
2016/07/25 PHP
PHP模糊查询技术实例分析【附源码下载】
2019/03/07 PHP
jquery下操作HTML控件的实现代码
2010/01/12 Javascript
奉献给JavaScript初学者的编写开发的七个细节
2011/01/11 Javascript
EXTJS记事本 当CompositeField遇上RowEditor
2011/07/31 Javascript
javascript从image转换为base64位编码的String
2014/07/29 Javascript
在jQuery中使用$而避免跟其它库产生冲突的方法
2015/08/13 Javascript
jquery判断当前浏览器的实现代码
2015/11/07 Javascript
javascript中递归的两种写法
2017/01/17 Javascript
Jquery实现跨域异步上传文件总结
2017/02/03 Javascript
angular ng-repeat数组中的数组实例
2017/02/18 Javascript
jQuery实现简单日期格式化功能示例
2017/09/19 jQuery
vue-cli脚手架config目录下index.js配置文件的方法
2018/03/13 Javascript
深入浅析Vue中的 computed 和 watch
2018/06/06 Javascript
详解Vue 的异常处理机制
2020/11/30 Vue.js
python3图片转换二进制存入mysql
2013/12/06 Python
python实现360皮肤按钮控件示例
2014/02/21 Python
Python中格式化format()方法详解
2017/04/01 Python
详解Python核心编程中的浅拷贝与深拷贝
2018/01/07 Python
Python基于生成器迭代实现的八皇后问题示例
2018/05/23 Python
python获取txt文件词向量过程详解
2019/07/05 Python
解决导入django_filters不成功问题No module named 'django_filter'
2020/07/15 Python
HTML5之HTML元素扩展(下)—增强的Form表单元素值得关注
2013/01/31 HTML / CSS
美国滑雪和滑雪板商店:Buckman
2018/03/03 全球购物
Omio俄罗斯:一次搜索公共汽车、火车和飞机的机票
2018/11/17 全球购物
斐乐美国官方网站:FILA美国
2019/03/01 全球购物
在DELPHI中调用存储过程和使用内嵌SQL哪种方式更好
2016/11/22 面试题
库房保管员岗位职责
2014/04/07 职场文书
公司应聘求职信
2014/06/21 职场文书
端午节活动总结
2014/08/26 职场文书
干部考察材料范文
2014/12/24 职场文书
安全先进个人材料
2014/12/29 职场文书
2015年房产经纪人工作总结
2015/05/15 职场文书
python实现的web监控系统
2021/04/27 Python