affine transform image

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
emery

affine transform image

Post 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 9337 times
Any suggestions?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: affine transform image

Post 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/
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
emery

Re: affine transform image

Post by emery »

Thank you! Using SRT distortion works *perfectly* =))))
emery

Re: affine transform image

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