PHP Imagerotate () Function

PHP

Syntax:
resource imagerotate ($image, $angle, $bgd_color, $ignore_transparent = 0)
Parameters:This function takes four parameters as above and described below:
  • $image:is returned by one of the image creation functions, such as like imagecreatetruecolor(). Used to create the size of the image.
  • $angle:this parameter contains the rotation angle in degrees. The rotation angle is used to rotate the image in a counterclockwise direction.
  • $bgd_color:This parameter contains the background color of the uncovered area after rotation.
  • $ignore_transparent:if this parameter is set and nonzero, then transparent colors are ignored.
Return Value:This function returns the image resource for the rotated image on success or False on error.The following programs illustrate the imagerotate() function in PHP:Program 1:  
// Assigning the image file to a variable $image_name = ' https://media.engineerforengineer.org/wp-content/uploads/engineerforengineer-15.png ' ;  
// Load image file $image = imagecreatefrompng ( $image_name );  
// Use imagerotate() to rotate the image $img = imagerotate ( $image , 180, 0);  
// Output image to browser header ( "Content-type: image / png" ); imagepng ( $img );  
?>
Output: Program 2:  
// Create the size of the image or blank image. $image = imagecreatetruecolor (500, 300);  
// Set the background color of the image. $bg = imagecolorallocate ( $image , 205, 220, 200);  
// Fill the background with the selected color above. imagefill ( $image , 0, 0, $bg );  
// Set the color of the ellipse. $col_ellipse = imagecolorallocate ( $image , 0, 102, 0);  
// Function for drawing a filled ellipse. imagefilledellipse ( $image , 250, 150, 400, 250, $col_ellipse );  
// Use imagerotate() to rotate the image $img = imagerotate ( $image , 90, 0);  
// Output image to browser header ( "Content-type: image / png" ); imagepng ( $img );  
?>
Output: Link: https://www.php.net/manual/en/function.imagerotate.php



Get Solution for free from DataCamp guru