How to create thumbnail images with a white 3px border using PHP?

advertisements

How to create thumbnail images with white 3px border using PHP?


Haven't actually tried this but I think something like this might work

<?php

/*
* Function to create a border around an image
*/
function drawBorder($image_name, $r = 0, $g = 0, $b = 0, $thickness = 1)
{
  $image = ImageCreateFromJPEG($image_name);
  $color = ImageColorAllocate($img, $r, $g, $b);

  $x1 = 0;
  $y1 = 0;
  $x2 = ImageSX($image) - 1;
  $y2 = ImageSY($image) - 1;

  for($i = 0; $i < $thickness; $i++)
  {
    ImageRectangle($image, $x1++, $y1++, $x2--, $y2--, $color);
  }

  return $image;
}

?>

Then run something like

<?php
header('Content-type: image/jpeg');
ImageJPEG(drawBorder("images/foo.jpg", 128, 128, 0, 3));
?>