为在PHP中创建的图像赋予边框

DEV*_*OPS 6 php gd

如何为使用PHP创建的图像赋予边框?

Rob*_*itt 13

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); 
    } 
}
Run Code Online (Sandbox Code Playgroud)

然后用法只是做.

$color = imagecolorallocate($img, 255, 0, 0);
drawBorder($img,$color, 255);
Run Code Online (Sandbox Code Playgroud)