PHP | ImagickDraw setGravity() Function
The ImagickDraw::setGravity() function is an inbuilt function in PHP which is used to set the text placement gravity when annotating with text.
Syntax:
bool ImagickDraw::setGravity( $gravity )
Parameters: This function accepts single parameter $gravity which is used to hold the value of gravity as GRAVITY_ constant.
List of GRAVITY constants are given below:
- imagick::GRAVITY_NORTHWEST (integer)
- imagick::GRAVITY_NORTH (integer)
- imagick::GRAVITY_NORTHEAST (integer)
- imagick::GRAVITY_WEST (integer)
- imagick::GRAVITY_CENTER (integer)
- imagick::GRAVITY_EAST (integer)
- imagick::GRAVITY_SOUTHWEST (integer)
- imagick::GRAVITY_SOUTH (integer)
- imagick::GRAVITY_SOUTHEAST (integer)
Return Value: This function does not return any value.
Below programs illustrate the ImagickDraw::setGravity() function in PHP:
Program 1:
<?php // Create an ImagickDraw object $draw = new ImagickDraw(); // Set the image filled color $draw->setFillColor('Green'); // Set the Font Size $draw->setFontSize(30); // Set the Gravity Position $draw->setGravity(5); // Set the font family $draw->setFontFamily('Ani'); // Set the text to be added $draw->annotation(30, 40, "GeeksForGeeks"); // Create new Imagick object $imagick = new Imagick();' // Set the image dimension $imagick->newImage(300, 150, 'white'); // Set the image format $imagick->setImageFormat("png"); // Draw the image $imagick->drawImage($draw); header("Content-Type: image/png"); // Display the image echo $imagick->getImageBlob(); ?> |
Output:

Program 2:
<?php // Create an ImagickDraw object $draw = new ImagickDraw(); // Set the image filled color $draw->setFillColor('green'); // Set the font size $draw->setFontSize(60); // Set the Gravity Position $draw->setGravity(2); // Set the text decoration $draw->setTextDecoration(4); // Set the text to be added $draw->annotation(50, 75, "GeeksForGeeks"); // Create new Imagick object $imagick = new Imagick(); // Set the image dimensions $imagick->newImage(600, 160, 'white'); // Set the image format $imagick->setImageFormat("png"); // Draw the image $imagick->drawImage($draw); header("Content-Type: image/png"); // Display the image echo $imagick->getImageBlob(); ?> |
Output:

Reference: http://php.net/manual/en/imagickdraw.setgravity.php
Recommended Posts:
- PHP | ImagickDraw arc() Function
- PHP | ImagickDraw setViewbox() Function
- PHP | ImagickDraw setFont() Function
- PHP | ImagickDraw setTextUnderColor() Function
- PHP | ImagickDraw setTextAntialias() Function
- PHP | ImagickDraw setTextDecoration() Function
- PHP | ImagickDraw getStrokeOpacity() Function
- PHP | ImagickDraw annotation() Function
- PHP | ImagickDraw skewY() Function
- PHP | ImagickDraw getStrokeWidth() Function
- PHP | ImagickDraw setTextAlignment() Function
- PHP | ImagickDraw setStrokeOpacity() Function
- PHP | ImagickDraw setFillColor() Function
- PHP | ImagickDraw translate() Function
- PHP | ImagickDraw skewX() Function
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.



