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 相关文章推荐
BBS(php &amp; mysql)完整版(五)
Oct 09 PHP
PHP Class&amp;Object -- PHP 自排序二叉树的深入解析
Jun 25 PHP
php代码审计比较有意思的例子
May 07 PHP
php中使用PHPExcel读写excel(xls)文件的方法
Sep 15 PHP
教你识别简单的免查杀PHP后门
Sep 13 PHP
php实现简单的上传进度条
Nov 17 PHP
详解php中的implements 使用
Jun 13 PHP
一个实用的php验证码类
Jul 06 PHP
PHP有序表查找之二分查找(折半查找)算法示例
Feb 09 PHP
thinkphp框架类库扩展操作示例
Nov 26 PHP
php使用pthreads v3多线程实现抓取新浪新闻信息操作示例
Feb 21 PHP
Yii 框架使用数据库(databases)的方法示例
May 19 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
综合图片计数器
2006/10/09 PHP
基于文本的留言簿
2006/10/09 PHP
PHP脚本的10个技巧(2)
2006/10/09 PHP
windows下PHP APACHE MYSQ完整配置
2007/01/02 PHP
PHP表单提交表单名称含有点号(.)则会被转化为下划线(_)
2011/12/14 PHP
关于更改Zend Studio/Eclipse代码风格主题的介绍
2013/06/23 PHP
Linux下安装PHP MSSQL扩展教程
2014/10/24 PHP
php自定义中文字符串截取函数substr_for_gb2312及substr_for_utf8示例
2016/05/28 PHP
PHP实现RTX发送消息提醒的实例代码
2017/01/03 PHP
详解PHP 二维数组排序保持键名不变
2019/03/06 PHP
浅谈laravel框架sql中groupBy之后排序的问题
2019/10/17 PHP
用Javascript做flash做的事..才完成的一个类.Auntion Action var 0.1
2007/02/23 Javascript
js小技巧--自动隐藏红叉叉
2007/08/13 Javascript
js DOM 元素ID就是全局变量
2012/09/20 Javascript
js构造函数、索引数组和属性的实现方式和使用
2014/11/16 Javascript
JavaScript中操作字符串小结
2015/05/04 Javascript
浅谈JavaScript中的作用域和闭包问题
2015/07/07 Javascript
纯JS焦点图特效实例(可一个页面多用)
2016/12/07 Javascript
HTML5 js实现拖拉上传文件功能
2020/11/20 Javascript
JavaScript对象引用与赋值实例详解
2017/03/15 Javascript
js用类封装pop弹窗组件
2017/10/08 Javascript
vue2.0与bootstrap3实现列表分页效果
2017/11/28 Javascript
[04:32]玩具屠夫中文语音节选
2020/08/23 DOTA
python处理cookie详解
2014/02/07 Python
Python判断变量是否为Json格式的字符串示例
2017/05/03 Python
Python爬虫信息输入及页面的切换方法
2018/05/11 Python
Flask框架URL管理操作示例【基于@app.route】
2018/07/23 Python
Python3安装psycopy2以及遇到问题解决方法
2019/07/03 Python
python对绑定事件的鼠标、按键的判断实例
2019/07/17 Python
python 实现快速生成连续、随机字母列表
2019/11/28 Python
奶茶专卖店创业计划书
2014/01/18 职场文书
2014年教师思想工作总结
2014/12/03 职场文书
委托书的样本
2015/01/28 职场文书
网聊搭讪开场白
2015/05/28 职场文书
新员工实习期个人工作总结
2015/10/15 职场文书
2016年教师党员创先争优承诺书
2016/03/24 职场文书