PHP GD draw image outline?

Discussion in 'PHP' started by The-host, Aug 16, 2009.

  1. #1
    Hi DigitalPoint members, I'm making a script for my friend using php gd and is stuck at this point here. He wants a 1px outline to the images generated using php gd, is this possible?

    NOTE: Image border isn't what he wants, he wants a 1px outline around the image itself.

    I know this is possible with text generated, but have no idea with images. I'm currently at a shop outside my house, thus will reply to those who helped me asap. :D

    Thanks!
     
    The-host, Aug 16, 2009 IP
  2. Gray Fox

    Gray Fox Well-Known Member

    Messages:
    196
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    130
    #2
    Simplest way of doing it, if you need more customizable function, contact me
    
    header('Content-type: image/png');
    $image = "your-image.jpg";
    list ($width, $height, $imageType) = getimagesize($image);
    $newWidth = $width + 2;
    $newHeight = $height + 2;
    $oldImage = imagecreatefromjpeg($image);
    $newImage = imagecreatetruecolor($newWidth, $newHeight);
    $borderColor = imagecolorallocate($newImage, 255, 0, 0);
    imagefill($newImage, 0, 0, $borderColor);
    imagecopyresampled($newImage, $oldImage, 1, 1, 0, 0, $width, $height, $width, $height);
    imagepng($newImage);
    imagedestroy($newImage);
    
    PHP:
     
    Gray Fox, Aug 16, 2009 IP