The Imagick::setImageOrientation() function is an inbuilt function in PHP which is used to set the image orientation. This function doesn’t actually rotate the image, it just changes the EXIF rotation info.
Syntax:
bool Imagick::setImageOrientation( int $orientation )
Parameters: This function accepts a single parameter $orientation which holds an integer value containing one of ORIENTATION constants. We can also pass a constant directly like setImageOrientation(imagick::ORIENTATION_BOTTOMRIGHT);.
List of ORIENTATION constants are given below:
- imagick::ORIENTATION_UNDEFINED (0)
- imagick::ORIENTATION_TOPLEFT (1)
- imagick::ORIENTATION_TOPRIGHT (2)
- imagick::ORIENTATION_BOTTOMRIGHT (3)
- imagick::ORIENTATION_BOTTOMLEFT (4)
- imagick::ORIENTATION_LEFTTOP (5)
- imagick::ORIENTATION_RIGHTTOP (6)
- imagick::ORIENTATION_RIGHTBOTTOM (7)
- imagick::ORIENTATION_LEFTBOTTOM (8)
Return Value: This function returns TRUE on success.
Below programs illustrate the Imagick::setImageOrientation() function in PHP:
Program 1:
<?php // Create a new imagick object $imagick = new Imagick( // Set the Orientation $imagick ->setImageOrientation(imagick::ORIENTATION_LEFTTOP); // Get the Orientation $orientation = $imagick ->getImageOrientation(); echo $orientation ; ?> |
Output:
5 // Which corresponds to imagick::ORIENTATION_LEFTTOP.
Program 2:
<?php // Create a new imagick object $imagick = new Imagick( // Set the Orientation $imagick ->setImageOrientation(imagick::ORIENTATION_RIGHTBOTTOM); // Get the Orientation $orientation = $imagick ->getImageOrientation(); echo $orientation ; ?> |
Output:
7 // Which corresponds to imagick::ORIENTATION_RIGHTBOTTOM.
Reference: https://www.php.net/manual/en/imagick.setimageorientation.php