2010-06-09 10 views

Odpowiedz

11
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); 
    } 
} 

Następnie użycie będzie po prostu zrobić.

$color = imagecolorallocate($img, 255, 0, 0); 
drawBorder($img,$color, 255); 
+0

Błąd. Poprosiłeś o kolor $ ale użyłeś $ color_black. – nebkat

+0

Ive zaktualizowałem mój post, przegląd pelase, błąd typowania górnika! – RobertPitt

+0

jest to właściwa metoda wyświetlania obrazów przy użyciu nagłówka PHP ("content-type: image/jpeg"); imagejpeg ($ image); – learner

2

Nie testowałem tego, ale myślę, że to wystarczy.

function addBorder($image, $width, $height) 
{ 
    $gd = imagecreatetruecolor($width, $height); 

    for($i = 0; $i<$height; $i++) 
    { 
     // add left border 
     imagesetpixel($image,0,$i, imagecolorallocate($gd, 0,0,0)); 
     // add right border 
     imagesetpixel($image,$width-1,$i, imagecolorallocate($gd, 0,0,0)); 
    } 
    for($j = 0; $j<$width; $j++) 
    { 
     // add bottom border 
     imagesetpixel($image,$j,0, imagecolorallocate($gd, 0,0,0)); 
     // add top border 
     imagesetpixel($image,$j,$height-1, imagecolorallocate($gd, 0,0,0)); 
    } 

    return $image; 
} 

$image = //your image 
$width = //your iimage width 
$height = //your image height 


$image = addBorder($image, $width, $height); 
+0

cześć sir to nie działa, obraz nie wyświetla. – learner

Powiązane problemy