Page 1 of 1

affine transform image

Posted: 2009-08-06T11:43:25-07:00
by emery
I cannot find any way around the two complementary bugs in Imagick that make it impossible to apply a tranformation matrix to an image.

The affineTransformImage function simply does _nothing_ no matter what parameters I manually provide to it, no matter what the state of the transformation matrix, it simply does nothing. I guess someone forgot to implement it.

But the functionality seems to still exist through ImagickDraw->composite, it's just buggy in that is loses the alpha channel after.

Code: Select all

	public function transformImage($img, $x, $y) {

		$draw = $this->createDraw();
		$draw->composite(Imagick::COMPOSITE_OVER, $x, $y, $img->getImageWidth(), $img->getImageHeight(), $img);		
		$result = $this->createBuffer();
		$result->drawImage($draw);

		return $result;
	}
This image is rotated 10 degrees through $draw->rotate(10). As you can see it has ugly aliasing.
run.php.png
run.php.png (144.44 KiB) Viewed 9574 times
Any suggestions?

Re: affine transform image

Posted: 2009-08-06T18:16:50-07:00
by anthony
Use Distort Images AffineProjection instead. For how you can use Image Distortion from IMagick see Mikko's Blog

Do not forget to enable the use of 'best-fit' and watch the virtual canvas offsets.

See the command line usage examples at
http://www.imagemagick.org/Usage/distor ... projection

For details of the meaning and handling of the matrix see
http://www.imagemagick.org/Usage/distorts/affine/

Re: affine transform image

Posted: 2009-08-07T18:36:12-07:00
by emery
Thank you! Using SRT distortion works *perfectly* =))))

Re: affine transform image

Posted: 2009-08-08T20:43:58-07:00
by emery
New problem: I can't get SRT to work for consecutive rotations, rendered in one step. Basically I have a single vector shape which I manipulate through rotate+translate to rotate around a pivot point. Then I later have to composite an image into the shape mask, so I use SRT to fit the image to the shape

But when I do consecutive rotate's at different pivot points to the shape, how can I apply the same transformation to an image of equal size?