PHP | Imagick setImageOrientation() Function

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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;
?>

chevron_right


Output:

 5 // Which corresponds to imagick::ORIENTATION_LEFTTOP.

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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;
?>

chevron_right


Output:

 7 // Which corresponds to imagick::ORIENTATION_RIGHTBOTTOM.

Reference: https://www.php.net/manual/en/imagick.setimageorientation.php



My Personal Notes arrow_drop_up

I love Open Source Culture have contributed to phpMyAdmin, LibreOffice, Ant-Design and Web is my passion

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.