bending text using imagick api

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
iscripts
Posts: 6
Joined: 2011-10-20T22:14:23-07:00
Authentication code: 8675308

bending text using imagick api

Post 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
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: bending text using imagick api

Post 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
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: bending text using imagick api

Post 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();
}

?>
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: bending text using imagick api

Post 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
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
iscripts
Posts: 6
Joined: 2011-10-20T22:14:23-07:00
Authentication code: 8675308

Re: bending text using imagick api

Post 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..
Post Reply