+

PHP Imagerectangle () Function

Syntax:
bool imagerectangle ($image, $x1, $y1, $x2, $y2, $color)  Parameters:this function takes six parameters as above and described below:
  • $image:is returned by one of the functions image creation such as imagecreatetruecolor(). Used to create the size of the image.
  • $x1:this parameter is used to set the top-left x-coordinate.
  • $y1: this parameter is used to set the top-left y-coordinate.
  • $x2:this parameter is used to set the bottom-right x coordinate.
  • $y2:this parameter is used to set the lower right y-coordinate.
  • $color:color identifier generated with imagecolorallocate().
Return Value:This function returns True on success or False on failure.The following programs illustrate the imagerectangle() functionin PHP:Program 1:  
// Create an image of the specified size $image = imagecreatetruecolor (400, 400);  
// Create image color $green = imagecolorallocate ( $image , 0, 153, 0); $white = imagecolorallocate ( $image , 255, 255, 255);  
// Draw a rectangle imagerectangle ( $image , 50, 50, 350, 350, $green ); imagerectangle ( $image , 100, 100, 300, 300, $white );  
// Display and free from memory header ( `Content-Type: image / jpeg` ); imagejpeg ( $image ); imagedestroy ( $image ); ?>
Output: Program 2:  
// Create image of specified size $image = imagecreatetruecolor (400, 400);  
// Set the background color of the image $background_color = imagecolorallocate ( $image , 255, 255, 255);  
// Fill the background with the selected color above imagefill ( $image , 0, 0, $background_color );  
// Create image color $green = imagecolorallocate ( $image , 0, 153, 0); $white = imagecolorallocate ( $image , 155, 53, 32);  
// Draw a rectangle imagerectangle ( $image , 50, 50, 350, 350, $green ); imagerectangle ( $image , 100, 100, 300, 300, $white );  
// Display and free from memory header ( `Content-Type: image / jpeg` ); imagejpeg ( $image ); imagedestroy ( $image ); ?>
Output: Link: http://php.net/manual/en/function.imagerectangle.php
Get Solution for free from DataCamp guru