rotating a label

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
david222
Posts: 7
Joined: 2012-04-11T13:01:38-07:00
Authentication code: 8675308

rotating a label

Post by david222 »

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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: rotating a label

Post by fmw42 »

david222
Posts: 7
Joined: 2012-04-11T13:01:38-07:00
Authentication code: 8675308

Re: rotating a label

Post by david222 »

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,

Code: Select all

convert background.jpg overlay.png -distort SRT '0,0 1 37 10,10' -composite target_image.jpg
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 !
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: rotating a label

Post by fmw42 »

try +distort rather than -distort, then it won't be cropped. Sorry, I forgot about that.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: rotating a label

Post by snibgo »

david222 wrote:... just to get the text to pivot correctly around the selected point ?
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).

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
EDIT: forgot to mention: each "+write info:" shows the page offsets, merely to show you what is happening. You can remove them.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: rotating a label

Post by fmw42 »

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.
david222
Posts: 7
Joined: 2012-04-11T13:01:38-07:00
Authentication code: 8675308

Re: rotating a label

Post by david222 »

fmw42 wrote:try +distort rather than -distort, then it won't be cropped. Sorry, I forgot about that.
yes ! that's it ! thank you !!
[w ow, that one character makes all the difference in the world... ]

snibgo wrote:
david222 wrote:... just to get the text to pivot correctly around the selected point ?
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).
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: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
EDIT: forgot to mention: each "+write info:" shows the page offsets, merely to show you what is happening. You can remove them.
this is actually very informative. thanks ! it definitely makes seeing what's going on a lot easier.

thanks to both of you for your input, i can now stop pulling my hair out. ;)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: rotating a label

Post by fmw42 »

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. :wink: :lol:
Post Reply