Share on Google+Share on Google+

PHP GD Draw Rectangle

Advertisement
This example shows how to draw rectangle in php gd.

<?php

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

$width = 350;

$height = 360;

$im = ImageCreateTrueColor($width, $height);

ImageAntiAlias($im, true);

$white = ImageColorAllocate($im, 255, 255, 255);

ImageFillToBorder($im, 0, 0, $white, $white);

$black = ImageColorAllocate($im, 0, 0, 0);

$blue = ImageColorAllocate($im, 0, 0, 255);

$r_width = 140;

$r_height = 90;

$r_x = 90;

$r_y = 40;

ImageRectangle($im, $r_x, $r_y, $r_x+$r_width, $r_y+$r_height, $black);

$r_width = 140;

$r_height = 90;

$r_x = 90;

$r_y = 180;

ImageFilledRectangle($im, $r_x, $r_y, $r_x+$r_width, $r_y+$r_height, $blue);

ImageJPEG($im);

ImageDestroy($im);

?>

After running the program you will get the following output

Advertisements

Posted on: November 4, 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.