The ImagickDraw::getTextAlignment() function is an inbuilt function in PHP which is used to get the alignment applied when annotating with text. It helps to format the text by making it stick to left, right or middle.
Syntax:
int ImagickDraw::getTextAlignment( void )
Parameters: This function doesn’t accept any parameter.
Return Value: This function returns an integer value corresponding to one of ALIGN constants.
List of ALIGN constants are given below:
- imagick::ALIGN_UNDEFINED (0)
- imagick::ALIGN_LEFT (1)
- imagick::ALIGN_CENTER (2)
- imagick::ALIGN_RIGHT (3)
Exceptions: This function throws ImagickException on error.
Below given programs illustrate the ImagickDraw::getTextAlignment() function in PHP:
Program 1:
<?php // Create a new ImagickDraw object $draw = new ImagickDraw(); // Get the text alignment $textAlignment = $draw->getTextAlignment(); echo $textAlignment; ?> |
Output:
0 // which corresponds to imagick::ALIGN_UNDEFINED
Program 2:
<?php // Create a new ImagickDraw object $draw = new ImagickDraw(); // Create a new imagick object $imagick = new Imagick(); // Create a image on imagick object $imagick->newImage(800, 250, 'white'); // Create a new ImagickDraw object $draw = new ImagickDraw(); // Align the text $draw->setTextAlignment(2); // Set the font size $draw->setFontSize(25); // Print the text $draw->annotation(250, 100, 'The text alignment here is ' . $draw->getTextAlignment()); // Align the text $draw->setTextAlignment(1); // Print the text with same x-coordinate $draw->annotation(250, 180, 'The text alignment here is ' . $draw->getTextAlignment()); // 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.gettextalignment.php
Recommended Posts:
- PHP | ImagickDraw scale() Function
- PHP | ImagickDraw polygon() Function
- PHP | ImagickDraw roundRectangle() Function
- PHP | ImagickDraw arc() Function
- PHP | ImagickDraw circle() Function
- PHP | ImagickDraw bezier() Function
- PHP | ImagickDraw rectangle() Function
- PHP | ImagickDraw line() Function
- PHP | ImagickDraw point() Function
- PHP | ImagickDraw skewX() Function
- PHP | ImagickDraw setStrokeWidth() Function
- PHP | ImagickDraw translate() Function
- PHP | ImagickDraw setStrokeOpacity() Function
- PHP | ImagickDraw setGravity() Function
- PHP | ImagickDraw setFillColor() Function
- PHP | ImagickDraw setFont() Function
- PHP | ImagickDraw setFontStyle() Function
- PHP | ImagickDraw setFontFamily() Function
- PHP | ImagickDraw setFontSize() Function
- PHP | ImagickDraw setFontWeight() 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.

