欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

php生成圆角图片的方法

程序员文章站 2022-09-15 16:20:53
本文实例讲述了php生成圆角图片的方法。分享给大家供大家参考。具体如下: 复制代码 代码如下:

本文实例讲述了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程序设计有所帮助。