I'm trying to include a conditional offset to the gravity centre of my text on my generated image. I've done some reading and apparently I can use geometry.
Here is the code:
Code: Select all
<?php
function process($inputdata)
{
$width = 400;
$height = 300;
$textBackground = new ImagickPixel('transparent');
$textColor = new ImagickPixel('#FFF');
$gradient = new Imagick();
//gradient:angle=angle in degrees
$gradient->newPseudoImage($width, $height, 'gradient:#3a7bd5-#3a6073');
$image = new Imagick();
$image->newImage($width, $height, $textBackground);
$gradient->setImageColorspace($image->getImageColorspace());
$draw = new ImagickDraw();
$draw->setFillColor($textColor);
$draw->setFontSize( 25 );
$draw->setGravity(Imagick::GRAVITY_CENTER );
//$draw->setGeometry(Imagick::Geometry +20 +20); --New code that doesn't work
$image->annotateImage($draw, 0, 0, 0, $inputdata);
$gradient->compositeImage($image, Imagick::COMPOSITE_OVER, 0, 0);
$gradient->setImageFormat('png');
header('Content-type: image/png');
echo $gradient;
return;
}
?>
Code: Select all
$draw->setGravity(Imagick::GRAVITY_CENTER );
$draw->setGeometry(Imagick::Geometry +20 +20);
Any help would be appreciated.
EDIT - I'm coming to the conclusion that this option exists in the command line interface but not in the PHP API?