Page 1 of 1
Rotation and Compsite
Posted: 2014-04-25T08:27:41-07:00
by Capt. Hack'em
I am attempting to rotate an image around a certain point and composite it directly onto a larger image. I cannot figure out how to do this. I've come close with distort, but nothing is working.
For example: if I have an image (red.png) that is a red box 75x50, I want to composite it at 50,50 on a 200x200 blank image with a 20 degree rotation. This is what I want:
This was as close as I could come:
convert blank.png red.png -background none -distort SRT "50,50 20" -composite blank.png
But that gave me:
Please help. This is driving me nuts!
Re: Rotation and Compsite
Posted: 2014-04-25T09:44:00-07:00
by snibgo
Code: Select all
convert -size 200x200 xc:none blank.png
convert -size 75x50 xc:red red.png
convert blank.png ( red.png -virtual-pixel None +distort SRT "0,0 1,20 50,50" ) -layers merge +repage blank4.png
Some problems with your version:
- "distort" is applied to both images, but you want it applied to only one. Parentheses cure this.
- "-distort" clips to the original size of red.png. You want to extend it, so use "+distort" ie plus.
- The default virtual method is "edge", so pixels smear as the image turns.
- "-composite" ignores offsets created by "distort". "-layers merge" takes them into account.
Re: Rotation and Compsite
Posted: 2014-04-25T09:47:28-07:00
by fmw42
Here are two ways to do it.
Code: Select all
convert -size 75x50 xc:red -background none -rotate 20 -background none -extent 200x200-50-50 result.png
Code: Select all
convert \( -size 200x200 xc:none \) \( -size 75x50 xc:red -background none -rotate 20 \) -geometry +50+50 -composite result.png
If on windows, remove all the \
See
http://www.imagemagick.org/Usage/canvas/#solid
http://www.imagemagick.org/Usage/basics/#parenthesis
http://www.imagemagick.org/Usage/layers/#convert
http://www.imagemagick.org/Usage/crop/#extent
Also in general
http://www.imagemagick.org/Usage/reference.html
http://www.imagemagick.org/Usage/
Also it is a good idea to always provide your IM version and platform, since syntax varies.
___________
Sorry snibgo, we were posting at the same time as often happens.
Re: Rotation and Compsite
Posted: 2014-04-27T07:27:07-07:00
by Capt. Hack'em
Thank you both. Those worked nicely.
I only have 1 remaining problem. After the rotate, I need the image to be the same size. In other words, if part of the newly rotated image goes outside the bounds, I want it to crop that off not expand the final image size. How would I do that?
Brady
PS...I'm uxing linux centos with ImageMagick 6.8.9-0 Q16 x86_64 2014-04-26 built from source.
Re: Rotation and Compsite
Posted: 2014-04-27T10:56:37-07:00
by fmw42
In other words, if part of the newly rotated image goes outside the bounds, I want it to crop that off not expand the final image size.
My composite command will do that. -composite clips to the bounds of the base image. The default gravity is northwest and the -geometry arguments are then from the top left corner of the base image to the top left corner of the background image. If your geometry arguments are negative or too large (near the bottom or right side), then some of the red will be clipped.
If you set -gravity center, then the geometry arguments are relative to the center of both images, so that the rotated red rectangle will be clipped to the bounds of the background image, if you shift the center to the top left corner of the base image.
Code: Select all
convert \( -size 200x200 xc:none \) \( -size 75x50 xc:red -background none -rotate 45 \) \
-gravity center -geometry -100-100 -composite result.png
see
http://www.imagemagick.org/Usage/layers/#convert
http://www.imagemagick.org/Usage/layers/#layers