PHP | Imagick getGravity() Function

The Imagick::getGravity() function is an inbuilt function in PHP which is used to get the global gravity property for the Imagick object.

Syntax:

int Imagick::getGravity( void )

Parameters: This function does not accept any parameters.

Exceptions: This function throws ImagickException on error.

Return Value: This function returns an integer value which represents the gravity constant.
List of GRAVITY constants are given below:



  • imagick::GRAVITY_NORTHWEST (1)
  • imagick::GRAVITY_NORTH (2)
  • imagick::GRAVITY_NORTHEAST (3)
  • imagick::GRAVITY_WEST (4)
  • imagick::GRAVITY_CENTER (5)
  • imagick::GRAVITY_EAST (6)
  • imagick::GRAVITY_SOUTHWEST (7)
  • imagick::GRAVITY_SOUTH (8)
  • imagick::GRAVITY_SOUTHEAST (9)

Below programs illustrate the Imagick::getGravity() function in PHP:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create a new imagick object
$imagick = new Imagick();
  
// Get the Gravity
$gravity = $imagick->getGravity();
  
echo $gravity;
?>

chevron_right


Output:

0 // Which means gravity is not set.

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create a new imagick object
$imagick = new Imagick(
  
// Set the Gravity
$imagick->setGravity(3);
  
// Get the Gravity
$gravity = $imagick->getGravity();
  
echo $gravity;
?>

chevron_right


Output:

3 // Which corresponds to imagick::GRAVITY_NORTHEAST.

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

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.



Improved By : gurrrung

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.