PHP imagerectangle() function

In this chapter you will learn:

  1. What is PHP imagerectangle() function
  2. Syntax for PHP imagerectangle() function
  3. Parameter for PHP imagerectangle() function
  4. Return value for PHP imagerectangle() function
  5. Example - PHP imagerectangle() function

Description

imagerectangle() creates a rectangle starting at the specified coordinates.

Syntax

PHP imagerectangle() function has the following syntax.

bool imagerectangle ( resource $image , int $x1 , int $y1 , int $x2 , int $y2 , int $color )

Parameter

PHP imagerectangle() function has the following parameters.

  • image - An image resource, returned by one of the image creation functions, such as imagecreatetruecolor().
  • x1 - Upper left x coordinate.
  • y1 - Upper left y coordinate 0, 0 is the top left corner of the image.
  • x2 - Bottom right x coordinate.
  • y2 - Bottom right y coordinate.
  • color - A color identifier created with imagecolorallocate().

Return

Returns TRUE on success or FALSE on failure.

Example


<?php/*j  a v  a 2  s  .com*/
// Create a 200 x 200 image
$canvas = imagecreatetruecolor(200, 200);

// Allocate colors
$pink = imagecolorallocate($canvas, 255, 105, 180);
$white = imagecolorallocate($canvas, 255, 255, 255);
$green = imagecolorallocate($canvas, 132, 135, 28);

// Draw three rectangles each with its own color
imagerectangle($canvas, 50, 50, 150, 150, $pink);
imagerectangle($canvas, 45, 60, 120, 100, $white);
imagerectangle($canvas, 100, 120, 75, 160, $green);

// Output and free from memory
header('Content-Type: image/jpeg');

imagejpeg($canvas);
imagedestroy($canvas);
?>

Next chapter...

What you will learn in the next chapter:

  1. What is PHP imagesetpixel() function
  2. Syntax for PHP imagesetpixel() function
  3. Parameter for PHP imagesetpixel() function
  4. Return value for PHP imagesetpixel() function
  5. Example - imagesetpixel() example
Home » PHP Tutorial » PHP Image Functions
PHP imagearc() function
PHP imagecreate() function
PHP imagecreatetruecolor () function
PHP imageellipse() function
PHP imagefilledarc() function
PHP imageline() function
PHP imagepolygon() function
PHP imagerectangle() function
PHP imagesetpixel() function
PHP imagettftext() function