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小偷的核心程序
Apr 09 PHP
应用开发中涉及到的css和php笔记分享
Aug 02 PHP
解析curl提交GET,POST,Cookie的简单方法
Jun 29 PHP
CI框架中集成CKEditor编辑器的教程
Jun 09 PHP
个人写的PHP验证码生成类分享
Aug 21 PHP
PHP改进计算字符串相似度的函数similar_text()、levenshtein()
Oct 27 PHP
ZF框架实现发送邮件的方法
Dec 03 PHP
PHP指定截取字符串中的中英文或数字字符的实例分享
Mar 18 PHP
PHP微信API接口类
Aug 22 PHP
php 中的closure用法详解
Jun 12 PHP
PHP基于ORM方式操作MySQL数据库实例
Jun 21 PHP
关于Anemometer图形化显示MySQL慢日志的工具搭建及使用的详细介绍
Jul 13 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中如何将数组变量写入文件
2013/06/06 PHP
Yii 访问 Gii(脚手架)时出现 403 错误
2018/06/06 PHP
extjs 学习笔记(二) Ext.Element类
2009/10/13 Javascript
Javascript页面添加到收藏夹的简单方法
2013/08/07 Javascript
jQuery学习笔记之基础中的基础
2015/01/19 Javascript
简单理解vue中Props属性
2016/10/27 Javascript
JS中使用new Date(str)创建时间对象不兼容firefox和ie的解决方法(两种)
2016/12/14 Javascript
require.js中的define函数详解
2017/07/10 Javascript
js canvas实现简单的图像扩散效果
2020/06/28 Javascript
Vue from-validate 表单验证的示例代码
2017/09/26 Javascript
Angular PWA使用的Demo示例
2019/01/31 Javascript
Vue实现类似Spring官网图片滑动效果方法
2019/03/01 Javascript
vue 开发企业微信整合案例分析
2019/12/02 Javascript
JS实现音量控制拖动
2020/01/15 Javascript
python远程登录代码
2008/04/29 Python
pymongo实现控制mongodb中数字字段做加法的方法
2015/03/26 Python
简单介绍Python中的len()函数的使用
2015/04/07 Python
python从网络读取图片并直接进行处理的方法
2015/05/22 Python
python logging 日志轮转文件不删除问题的解决方法
2016/08/02 Python
浅谈python中的变量默认是什么类型
2016/09/11 Python
Django1.9 加载通过ImageField上传的图片方法
2018/05/25 Python
Python 从一个文件中调用另一个文件的类方法
2019/01/10 Python
50行Python代码获取高考志愿信息的实现方法
2019/07/23 Python
Python字符串处理的8招秘籍(小结)
2019/08/13 Python
处理textarea中的换行和空格
2019/12/12 HTML / CSS
领先的荷兰线上超市:荷兰之家Holland at Home(支持中文)
2021/01/21 全球购物
质检员岗位职责
2013/12/17 职场文书
小学生演讲稿
2014/01/12 职场文书
幼儿园小班植树节活动方案
2014/03/04 职场文书
《社戏》教学反思
2014/04/15 职场文书
公司授权委托书范文
2014/09/21 职场文书
先进工作者个人总结
2015/02/15 职场文书
应聘教师求职信范文
2015/03/20 职场文书
个人工作违纪检讨书
2015/05/05 职场文书
初中政治教学工作总结
2015/08/13 职场文书
改造DE1103三步曲
2022/04/07 无线电