PHP GD Draw Rectangle


 

PHP GD Draw Rectangle

This example shows how to draw rectangle in php gd.

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

Ads