You could use Imagick. Imagick is a native php extension to create and modify images. It has a specific function for that called Imagick::borderImage.
Something like this could do the job:
$image = new Imagick('your_image.jpg');
$color=new ImagickPixel();
$color->setColor("rgb(100,200,50)");
$image->borderImage($color,1,1);
$image->writeImage('your_bordered_image.jpg');
You might have to adjust those code lines slightly, I just have thrown them together.