tags:

views:

512

answers:

5

Hi.

Is there any simple way to add a image border around an image?

Reason is I want to create a drop-shadow effect around the image.

The images are loaded as thumbnails and are 110x75 px... Im thinking about creating a shadow border, but dont know how to add this to around the image, anybody know a way?

PHP preferrably...

+2  A: 

You can use the GD library or ImageMagick to alter the actual image in PHP, but you can also achieve a similar effect in CSS, if it is only required on a web page.

There is a complete tutorial on doing it with PHP and GD here:

Colin Pickard
oh, I will laugh hard when your server runs out of memory while converting hundreds of images to their image-with-shadows equivalents..
rochal
I'm not sure what you mean by this. This will not use a large amount of memory by modern standards. If it becomes a concern, there is no need to process images in real time, unless you are generating a unique image for each user. Just generate an image-with-shadows once, store it and reference that instead. Beware premature optimization, we're not in 1998 any more.
Colin Pickard
A: 

If you want to do it using PHP, try the PHP GD library: http://php.net/manual/en/book.image.php

Using CSS would be an easier option, using the border property.

Trevor
+1  A: 

You would need to use CSS to create this effect. There are several options.

 .img{
      border-top:none;
      border-left:none;
      border-right:solid 2px #dddddd;
      border-bottom:solid 2px #dddddd;
 }

is the simplest but it does not look so great.

To make even better shadows you can use a plugin for jQuery such as the shadows plugin. It creates nice drop shadow effects on any element on the page.

Vincent Ramdhanie
How do i get jquery to work, hear alot about it...Is it just the <script src="jquery file here"> that points to some library or is ther more to it?
Camran
Piskvor
+1  A: 

If this is just visual sprinkles you could try the CSS3 box-shadow property. It will only work on Firefox, Safari and Chrome though, so it's a only a "progressive enhancement". This tutorial should help.

Alternatively you can use this CSS for a basic effect. gallery is whatever class name you give to the element surrounding the images (i.e. via <div class="gallery">...</div>). Width/height are optional, but if the images are all the same size then it's better to use CSS instead of the width/height attributes on the images themselves.

.gallery img {
    width: 100px;
    height: 75px;
    border-width: 0 3px 3px 0;
    border-style: solid;
    border-color: #ccc;
}
DisgruntledGoat
A: 

function addBorderpng($add){ $border=5; $im=imagecreatefrompng($add); $width=imagesx($im); $height=imagesy($im);
$img_adj_width=$width+(2*$border); $img_adj_height=$height+(2*$border); $newimage=imagecreatetruecolor($img_adj_width,$img_adj_height);

$border_color = imagecolorallocate($newimage, 255, 255, 255);
imagefilledrectangle($newimage,0,0,$img_adj_width,

$img_adj_height,$border_color);

imagecopyresized($newimage,$im,$border,$border,0,0,

$width,$height,$width,$height); imagepng($newimage,$add,9); chmod("$add",0666);

}

learner