我看到这篇关于使用 PHP 对图像应用圆角的博客文章:http: //salman-w.blogspot.ca/2009/05/generate-images-with-round-corners-on.html
代码如下
<?php
/*
* Apply Round Corner PHP-GD
* http://salman-w.blogspot.com/2009/05/generate-images-with-round-corners-on.html
*
* Adds rounded corners to the specified image
*/
/*
* source: path or url of a gif/jpeg/png image -- php fopen url wrapper must be enabled if using url
* radius: corner radius in pixels -- default value is 10
* colour: corner colour in rgb hex format -- default value is FFFFFF
*/
$source = $_GET["source"];
$radius = isset($_GET["radius"]) ? $_GET["radius"] : 10;
$colour = isset($_GET["colour"]) ? $_GET["colour"] : "FFFFFF";
/*
* open source image and calculate properties
*/
list($source_width, $source_height, $source_type) = getimagesize($source);
switch ($source_type) {
case IMAGETYPE_GIF:
$source_image = imagecreatefromgif($source);
break;
case IMAGETYPE_JPEG:
$source_image = imagecreatefromjpeg($source);
break;
case IMAGETYPE_PNG:
$source_image = imagecreatefrompng($source);
break;
}
/*
* create mask for top-left corner in memory
*/
$corner_image = imagecreatetruecolor(
$radius,
$radius
);
$clear_colour = imagecolorallocate(
$corner_image,
0,
0,
0
);
$solid_colour = imagecolorallocate(
$corner_image,
hexdec(substr($colour, 0, 2)),
hexdec(substr($colour, 2, 2)),
hexdec(substr($colour, 4, 2))
);
imagecolortransparent(
$corner_image,
$clear_colour
);
imagefill(
$corner_image,
0,
0,
$solid_colour
);
imagefilledellipse(
$corner_image,
$radius,
$radius,
$radius * 2,
$radius * 2,
$clear_colour
);
/*
* render the top-left, bottom-left, bottom-right, top-right corners by rotating and copying the mask
*/
imagecopymerge(
$source_image,
$corner_image,
0,
0,
0,
0,
$radius,
$radius,
100
);
$corner_image = imagerotate($corner_image, 90, 0);
imagecopymerge(
$source_image,
$corner_image,
0,
$source_height - $radius,
0,
0,
$radius,
$radius,
100
);
$corner_image = imagerotate($corner_image, 90, 0);
imagecopymerge(
$source_image,
$corner_image,
$source_width - $radius,
$source_height - $radius,
0,
0,
$radius,
$radius,
100
);
$corner_image = imagerotate($corner_image, 90, 0);
imagecopymerge(
$source_image,
$corner_image,
$source_width - $radius,
0,
0,
0,
$radius,
$radius,
100
);
/*
* output the image -- revise this step according to your needs
*/
header("Content-type: image/png");
imagepng($source_image);
?>
我的问题是,如何在使用 html 表单上传的图像上使用此代码,以便图像自动保存并应用圆角?IE。我如何:
- 将代码应用于上传/上传的图像
- 将此图像输出到本地文件而不是提供给浏览器