Open In App

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:

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

Program 1:




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

Output:

0 // Which means gravity is not set.

Program 2:




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

Output:

3 // Which corresponds to imagick::GRAVITY_NORTHEAST.

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

Article Tags :