2010-06-09 18 views
6

¿Cómo doy un borde a una imagen creada usando PHP?Dar borde a la imagen creada en PHP

+0

posible duplicado de [cómo agregar una imagen-borde alrededor de una imagen?] (Http://stackoverflow.com/questions/1589550/how-to-add-image-border-around-an-image) – Gordon

Respuesta

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

Entonces, el uso simplemente haría.

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

Error. Pidió $ color pero usó $ color_black. – nebkat

+0

¡He actualizado mi publicación, pelase review, miner typing error! – RobertPitt

+0

este es el método correcto para mostrar imágenes usando PHP header ("content-type: image/jpeg"); imagejpeg ($ imagen); – learner

2

No probé esto, pero creo que hará el truco.

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

hola señor, no está funcionando. La imagen no se muestra. – learner

Cuestiones relacionadas