Open In App

PHP | Imagick setImageOrientation() Function

Last Updated : 28 Nov, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report
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
<?php

// Create a new imagick object
$imagick = new Imagick(
'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png');

// 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
<?php

// Create a new imagick object
$imagick = new Imagick(
'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png');

// 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

Next Article

Similar Reads