Friday, October 17, 2025
HomeLanguagesPHP | Imagick setImageOrientation() Function

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:




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

RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS