Home Tutorial Php Phpgd PHP GD Draw Rectangle

 
 

PHP GD Draw Rectangle
Posted on: November 4, 2009 at 12:00 AM
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

Related Tags for PHP GD Draw Rectangle:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.