Affine Translate and preserve alpha

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
latest33

Affine Translate and preserve alpha

Post by latest33 »

Trying to translate an image that is mostly transparent. There is a set of several images (will be processed one by one) that need to have their images shifted over a set amount. However, using:

convert test.png -affine 1,0,0,1,50,100 -transform output.png

However, the image doesn't change. I read that I need to flatten.

convert test.png -affine 1,0,0,1,50,100 -transform -flatten output.png

However, this puts a white background. I'm trying to find a way to keep the alpha.

Thank you.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Affine Translate and preserve alpha

Post by fmw42 »

what do you mean by translate / shift? what happens when you shift -- do you want to add extra area or just crop off the part shifted off the image size?

if you just want to loose some data, then just crop it to the center you need.

you can use -roll (but it has wrap around)

or you can use -distort SRT to do the translate. you may need to add -channel rgba -alpha on to preserve the transparency.

see -distort SRT http://www.imagemagick.org/Usage/distorts/#srt

use scale of 1 and angle of 0

you may need +distort to make the size bigger for the amount shifted

also see -distort affine under http://www.imagemagick.org/Usage/distor ... rol_points

that may be just what you want but use -virtual-pixel transparent for the fill-in of transparent
Last edited by fmw42 on 2010-01-20T16:30:27-07:00, edited 2 times in total.
latest33

Re: Affine Translate and preserve alpha

Post by latest33 »

fmw42 wrote:what do you mean by translate / shift? what happens when you shift -- do you want to add extra area or just crop off the part shifted off the image size?

if you just want to loose some data, then just crop it to the center you need.

you can use -roll (but it has wrap around)

or you can use -distort SRT to do the translate. you may need to add -channel rgba -alpha on to preserve the transparency.

see -distort SRT http://www.imagemagick.org/Usage/distorts/#srt

use scale of 1 and angle of 0

you may need +distort to make the size bigger for the amount shifted
That seems to have done it. I appreciate that.
Post Reply