php生成圆角图片的要领

来源: 电脑维修教程 阅读:     发表时间:

php生成圆角图片的要领 这篇文章主要介绍了php生成圆角图片的要领,涉及php操纵图片的技巧,非常具有实用价值,需要的伴侣可以参考下 本文实例讲述了php生

<?php生成圆角图片的要领

这篇文章主要介绍了<?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措施设计有所帮手。

电脑维修技术

以上是:解决php生成圆角图片的要领问题的详细资料教程