Jump to content

Add border to image with transparency.


53329

Recommended Posts

Title says it all but here is the code I have for reference anyway.  Is there a way to add a border around the edge of this image without copying it?  Keep in mind that the image has transparency.

 

<?php
$im = imagecreatefromgif("test.gif");
header("Content-type: image/gif");
imagegif($im);
imagedestroy($im);
?>

 

Thanks in advance for any help.

Link to comment
Share on other sites

Fixed it.  Here is for anyone else as I couldn't find this online.

<?php
$im = imagecreatefromgif("test.gif");
$width=imagesx($im);
$height=imagesx($im);
$border_color = imagecolorallocatealpha($im, 0, 0, 0, 0);
imageline($im, 0, 0, ($width-1), 0, $border_color);
imageline($im, 0, ($height-1), ($width-1), ($height-1), $border_color);
imageline($im, 0, 0, 0, ($height-1), $border_color);
imageline($im, ($width-1), 0, ($width-1), ($height-1), $border_color);
header("Content-type: image/gif");
imagegif($im);
imagedestroy($im);
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.