Page 1 of 1

bending text using imagick api

Posted: 2011-11-14T05:32:45-07:00
by iscripts
greetings everyone..

i have run into an issue with bending text using the imagick api. our server hosting team decided to block all shell commands which were being used earlier to execute commands in imagmagick. so i had to move on to the imagick api that is available for php. while i was able to find functions for almost every other command in imagemagick, this one, the one related to bending of texts eludes me.

i was using the distort arc method to accomplish text bending earlier

Code: Select all

-distort Arc 90
after looking up the list of functions available in imagick i found this one:-

Code: Select all

$image  = new Imagick();
$draw   = new ImagickDraw();
$pixel  = new ImagickPixel('gray');

$image->newImage(1225, 1225, $pixel);
$image->setGravity(imagick::GRAVITY_CENTER);

$draw->setFont('arial');
$draw->setFillColor("#CCCCCC");
$draw->setFontSize(48);

$image->annotateImage($draw, 0, 48, 0, "HELLO WORLD");
$image->paintTransparentImage('gray', 0.0, 10);

$image->distortImage( Imagick::DISTORTION_ARC, array(90), true );

$image->trimImage(0);
$image->setImageFormat('png');

			
ob_start();
header("Content-type: image/png");
echo $image;
the second parameter is supposed to be an array, but what values have to be passed to get the 90 degree bend, i am not sure. using the above code, the text does bend but at an awkward angle. can anyone point me in the right direction?

regards

Re: bending text using imagick api

Posted: 2011-11-14T08:29:26-07:00
by el_supremo
I don't know or use PHP but that does appear to be the correct way to use distort according to http://ca.php.net/manual/en/function.im ... timage.php

I have done the same kind of thing in C and it works. See the code for text effect 3 in http://members.shaw.ca/el.supremo/Magic ... ffects.htm which is from "Eight text effects in one function" in my MagickWand examples in C - the link is in my sig below.

Pete

Re: bending text using imagick api

Posted: 2011-11-14T09:56:53-07:00
by Bonzo
This worked for me but I can not test at the moment as I do not have Imagick installed. I know there were problems and a lot depends on what version of Imagick you have; Imagick is not very well documented and is not supported very well either.

fmw42 sorted the problem for me : )

Code: Select all

<?php

$width = 500;

$height = 100;

try
{

$im = new Imagick();

$draw = new ImagickDraw();

$draw->setFont('../arial.ttf');

$draw->setFontSize( 120 );

$draw->setGravity( Imagick::GRAVITY_CENTER );

$pixel = new ImagickPixel( "lightblue" );

$text = 'Anthony';

$im->newImage($width, $height, $pixel);

$im->annotateImage($draw, 0, 0, 0, $text);

$im->setImageVirtualPixelMethod( Imagick::VIRTUALPIXELMETHOD_WHITE );

$arcArray = array(360);

$im->distortImage( Imagick::DISTORTION_ARC, $arcArray, false );

$im->writeImage( $output );

}

catch(Exception $e)
{
        echo $e->getMessage();
}

?>

Re: bending text using imagick api

Posted: 2011-11-14T19:11:28-07:00
by anthony
It may be that the array must be first saved into an a array variable, and not directly given.

It is nice to see Disort had been added to IMagick for PHP

Re: bending text using imagick api

Posted: 2011-11-14T22:54:02-07:00
by iscripts
thanks everyone for your replies esp. bonzo, it was a silly mistake on my part, i was using the wrong object to make the function call. i was using

Code: Select all

$image->setGravity( Imagick::GRAVITY_CENTER );
instead of

Code: Select all

$draw->setGravity( Imagick::GRAVITY_CENTER );
it works perfectly now.. thanks again..