Share on Google+Share on Google+

PHP GD Add Border to image

In this PHP tutorial we know about how to add border to the images in the PHP GD Library.


$im = imagecreate(200, 60);

$bg = imagecolorallocate($im, 225, 225, 225);

$textcolor = imagecolorallocate($im, 0, 0, 255);

imagestring($im, 5, 30, 20, "Roseindia", $textcolor);

$bordercolors = imagecolorallocate($im, 255, 255, 20); //Define border color Yellow

$x = 0;

$y = 0;

$w = imagesx($im) - 1;

$h = imagesy($im) - 1;

imageline($im, $x,$y,$x,$y+$h,$bordercolors);

imageline($im, $x,$y,$x+$w,$y,$bordercolors);

imageline($im, $x+$w,$y,$x+$w,$y+$h,$bordercolors);

imageline($im, $x,$y+$h,$x+$w,$y+$h,$bordercolors);

header("Content-type: image/png");



After running the program you will get the following output


Posted on: October 30, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.


Advertisement null