Set an offset from gravity centre
Posted: 2017-02-25T05:23:37-07:00
Hi,
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:
This is the code I tried to use:
Which in theory should offset the text from the gravity center, however when I try it it stops my image generating. I think I have made a mistake because the only example code I can find is for the command line, not for the php interface.
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?
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?