The imagerotate() function is an inbuilt function in PHP which is used to rotate an image with a given angle in degrees. The rotation center of the image is center.
Syntax:
resource imagerotate( $image, $angle, $bgd_color, $ignore_transparent = 0 )
Parameters: This function accepts four parameters as mentioned above and described below:
- $image: It is returned by one of the image creation functions, such as imagecreatetruecolor(). It is used to create size of image.
- $angle: This parameter holds the rotation angle in degrees. The rotation angle is used to rotate an image in anticlockwise direction.
- $bgd_color: This parameter holds the background color of uncovered zone after rotation.
- $ignore_transparent: If this parameter set and non-zero then transparent colors are ignored.
Return Value: This function returns an image resource for the rotated image on success, or False on failure.
Below programs illustrate the imagerotate() function in PHP:
Program 1:
<?php
$image_name =
$image = imagecreatefrompng( $image_name );
$img = imagerotate( $image , 180, 0);
header( "Content-type: image/png" );
imagepng( $img );
?>
|
Output:

Program 2:
<?php
$image = imagecreatetruecolor(500, 300);
$bg = imagecolorallocate( $image , 205, 220, 200);
imagefill( $image , 0, 0, $bg );
$col_ellipse = imagecolorallocate( $image , 0, 102, 0);
imagefilledellipse( $image , 250, 150, 400, 250, $col_ellipse );
$img = imagerotate( $image , 90, 0);
header( "Content-type: image/png" );
imagepng( $img );
?>
|
Output:

Reference: https://www.php.net/manual/en/function.imagerotate.php