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
$draw = new ImagickDraw();
$textAlignment = $draw ->getTextAlignment();
echo $textAlignment ;
?>
|
Output:
0 // which corresponds to imagick::ALIGN_UNDEFINED
Program 2:
<?php
$draw = new ImagickDraw();
$imagick = new Imagick();
$imagick ->newImage(800, 250, 'white' );
$draw = new ImagickDraw();
$draw ->setTextAlignment(2);
$draw ->setFontSize(25);
$draw ->annotation(250, 100, 'The text alignment here is '
. $draw ->getTextAlignment());
$draw ->setTextAlignment(1);
$draw ->annotation(250, 180, 'The text alignment here is '
. $draw ->getTextAlignment());
$imagick ->drawImage( $draw );
$imagick ->setImageFormat( 'png' );
header( "Content-Type: image/png" );
echo $imagick ->getImageBlob();
?>
|
Output:

Reference: https://www.php.net/manual/en/imagickdraw.gettextalignment.php