为在PHP中创建的图像提供边框
问题描述:
如何为使用PHP创建的图像添加边框?
How do I give a border to an image created using PHP?
答
function drawBorder(&$img, &$color, $thickness = 1)
{
$x1 = 0;
$y1 = 0;
$x2 = ImageSX($img) - 1;
$y2 = ImageSY($img) - 1;
for($i = 0; $i < $thickness; $i++)
{
ImageRectangle($img, $x1++, $y1++, $x2--, $y2--, $color);
}
}
然后用法就可以了.
$color = imagecolorallocate($img, 255, 0, 0);
drawBorder($img,$color, 255);