How do I use Imagick->affineTransformImage()?

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
flashape

How do I use Imagick->affineTransformImage()?

Post by flashape »

I'm trying to transform an image using Imagick->affineTransformImage(), then compose that image onto an existing image. However when I compose the image, it's just positioned at the x,y specified by the call to compositeImage() with no transformation.

Here's what I am attempting:

Code: Select all


$image = new IMagick();
$image->readImageBlob($imageContent);  //$imageContent is image data loaded from another server.

$draw = new ImagickDraw();
$draw->affine( $this->convertFlashMatrix( $frameVO->matrix) ); //$frameVO is an object sent from flash
$image->affineTransformImage($draw);

// layeredImage is a previously existing Imagick object
$this->layeredImage->compositeImage( $image, Imagick::COMPOSITE_OVER, 200, 200);


//converts a matrix object sent from flash to the expected array for ImagickDraw->affine()
function convertFlashMatrix($flashMatrix){
	$imagickMatrix = array();
		
	$imagickMatrix['sx'] = $flashMatrix['a'];
	$imagickMatrix['sy'] = $flashMatrix['d'];
	$imagickMatrix['rx'] = $flashMatrix['b'];
	$imagickMatrix['ry'] = $flashMatrix['c'];
	$imagickMatrix['tx'] = $flashMatrix['tx'];
	$imagickMatrix['ty'] = $flashMatrix['ty'];

	return $imagickMatrix;
		
}
I'm sure I'm missing a step somewhere here, but I can't figure out what it is. Any help is appreciated.

Thanks,

Rich
flashape

Re: How do I use Imagick->affineTransformImage()?

Post by flashape »

i think i figured it out...or actually I figured out a different way to do what I wanted to do:

Code: Select all

$image = new IMagick();
$image->readImageBlob($imageContent);  //$imageContent is image data loaded from another server.

$draw = new ImagickDraw();
//set affine transformation in the imagickdraw object
$draw->affine( $this->convertFlashMatrix( $frameVO->matrix) );

//composite the image i want transformed into the draw object
$draw->composite(Imagick::COMPOSITE_OVER,0,0, -1, -1, $image);

//draw the draw object into the layered image
$this->layeredImage->drawImage($draw);
$draw->destroy();
Post Reply