Here is a code sample that will draw a border. I have used the GET
variable to call the image.
If you for example put this code in your images folder, you can call example.org/images/resize.php?path=image.jpg
, without modifying the original image. You can even use mod_rewrite (assuming you are using apache) to apply this filter.
However, this may affect the performance (doing it on the fly), so I recommend at least caching the images on the server, or just saving them to disk.
<?php
$img = ImageCreateFromJPEG($_GET['path']);
// Draw border
$color_black = ImageColorAllocate($img, 0, 0, 0);
drawBorder($img, $color_black, 10);
// Output
header('Content-type: image/jpeg');
ImageJPEG($img);
// Draw a border
function drawBorder(&$img, &$color, $thickness)
{
$x = ImageSX($img);
$y = ImageSY($img);
for($i = 0; $i < $thickness; $i++)
ImageRectangle($img, 0, 0, $x, $y--, $color_black);
}
?>