PHP | ImagickDraw getGravity() Function

The ImagickDraw::getGravity() function is an inbuilt function in PHP which is used to get the text placement gravity used when annotating with text.
Syntax:
int ImagickDraw::getGravity( void )
Parameters: This function doesn’t accepts any parameters.
Return Value: This function returns an integer value corresponding to one of GRAVITY constants or 0 when it is not set.
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 ImagickDraw::getGravity() function in PHP:
Program 1:
| <?php  Â// Create a new ImagickDraw object $draw= newImagickDraw();  Â// Get the font Gravity $Gravity= $draw->getGravity(); echo$Gravity; ?>  | 
Output:
0 // Which is the default value.
Program 2:
| <?php  Â// Create a new ImagickDraw object $draw= newImagickDraw();  Â// Set the font Gravity $draw->setGravity(8);  Â// Get the font Gravity $Gravity= $draw->getGravity(); echo$Gravity; ?>  | 
Output:
8
Program 3:
| <?php  Â// Create a new imagick object $imagick= newImagick();  Â// Create a image on imagick object $imagick->newImage(800, 250, 'black');  Â// Create a new ImagickDraw object $draw= newImagickDraw();  Â// Set the fill color $draw->setFillColor('cyan');  Â// Set the font size $draw->setFontSize(20);  Â// Annotate a text to (50, 100) $draw->annotation(50, 100,      'The gravity here is '. $draw->getGravity());  Â// Set the gravity $draw->setGravity(3);  Â// Annotate a text to (50, 100) $draw->annotation(50, 100,      'The gravity here is '. $draw->getGravity());  Â// Render the draw commands $imagick->drawImage($draw);  Â// Show the output $imagick->setImageFormat('png'); header("Content-Type: image/png"); echo$imagick->getImageBlob(); ?>  | 
Output:
Reference: https://www.php.net/manual/en/imagickdraw.getgravity.php
 
				 
					



