i want to composite a graphic image composed of text on a background, rotated by an arbitrary amount. the origin of rotation, and therefore the placement point on the background, must always be located at the upper left corner of the unrotated textual image, regardless of the angle or rotation. i've tried lots and lots of combinations of composite and convert, different types of -gravity, and even tried calculating a new -geometry depending on the angle of the rotation -- nothing works consistently. for example, an image rotated to 90° places the origin of rotation at the lower left of the text image label, while rotating the image -90° places the origin at the upper right. it's even more difficult when the rotation is an off-square angle, e.g. 37°, in which case the origin seems to be the upper left corner of a bounding rectangle placed around the text image. is there any way i can do what i want, w/o having to recalculate the -geometry origin w/sine+cosine values just to get the text to pivot correctly around the selected point ?
thanks.
rotating a label
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: rotating a label
try -distort SRT. See http://www.imagemagick.org/Usage/distorts/#srt
Re: rotating a label
thanks for replying, fmw42.
that doesn't seem to be quite it, either. what it looks like is happening is the overlay image is being rotated/translated within an invisible bounding box of the same dimensions as its unrotated image, so while the overlay is definitely being rotated, its edges are cropped. i've tried several different orderings of arguments, each w/different - but equally unsatisfactory - results. for example,
this does place the overlay image onto the background rotated by 37°, but cuts off most of the overlay. any ideas what i'm doing wrong ?
thanks again !
that doesn't seem to be quite it, either. what it looks like is happening is the overlay image is being rotated/translated within an invisible bounding box of the same dimensions as its unrotated image, so while the overlay is definitely being rotated, its edges are cropped. i've tried several different orderings of arguments, each w/different - but equally unsatisfactory - results. for example,
Code: Select all
convert background.jpg overlay.png -distort SRT '0,0 1 37 10,10' -composite target_image.jpg
thanks again !
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: rotating a label
try +distort rather than -distort, then it won't be cropped. Sorry, I forgot about that.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: rotating a label
I don't understand what you mean by rotation "around the selected point". When an image is rotated, it looks the same whichever point is the centre of rotation (provided the result contains the entire image).david222 wrote:... just to get the text to pivot correctly around the selected point ?
But I will guess at what you want. Suppse you want a 100x50 red rectangle on a 300x300 blue background. You want to rotate the red rectangle by 37 degrees, positioned so the top-left (ie 0,0) pixel is on the blue rectangle at coordinate 50,30. This will do that. Windows BAT syntax.
Code: Select all
%IM%convert ^
-size 300x300 xc:Blue ^
( ^
-size 100x50 xc:red ^
-virtual-pixel None ^
+distort SRT 0,0,1,37,0,0 ^
+write info: ^
-repage "+50+30^!" ^
+write info: ^
) ^
-layers merge ^
s.png
snibgo's IM pages: im.snibgo.com
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: rotating a label
Please note that syntax is different for Windows and Unix systems. So alway provide your IM version and what platform you are using when you ask a question.
Re: rotating a label
yes ! that's it ! thank you !!fmw42 wrote:try +distort rather than -distort, then it won't be cropped. Sorry, I forgot about that.
[w ow, that one character makes all the difference in the world... ]
agreed. i guess i should have phrased that as, '...to get the text to pivot around a specific point on the background image.'snibgo wrote:I don't understand what you mean by rotation "around the selected point". When an image is rotated, it looks the same whichever point is the centre of rotation (provided the result contains the entire image).david222 wrote:... just to get the text to pivot correctly around the selected point ?
this is actually very informative. thanks ! it definitely makes seeing what's going on a lot easier.snibgo wrote:But I will guess at what you want. Suppse you want a 100x50 red rectangle on a 300x300 blue background. You want to rotate the red rectangle by 37 degrees, positioned so the top-left (ie 0,0) pixel is on the blue rectangle at coordinate 50,30. This will do that. Windows BAT syntax.EDIT: forgot to mention: each "+write info:" shows the page offsets, merely to show you what is happening. You can remove them.Code: Select all
%IM%convert ^ -size 300x300 xc:Blue ^ ( ^ -size 100x50 xc:red ^ -virtual-pixel None ^ +distort SRT 0,0,1,37,0,0 ^ +write info: ^ -repage "+50+30^!" ^ +write info: ^ ) ^ -layers merge ^ s.png
thanks to both of you for your input, i can now stop pulling my hair out.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: rotating a label
I once new a guy who rubbed a hair restoring into his scalp for many months to regrow new hair. Afterwards, he had the hairiest fingertips you ever saw.