fmw42 wrote:For 30 degrees:
convert dial.gif \( arrow.gif -virtual-pixel transparent +distort SRT "22,391
30" \) \
-geometry +328+0 -composite arrow_dial_30.gif
see -distort SRT at
http://www.imagemagick.org/Usage/distorts/#srt
I rotated about the bottom center of the arrow by 30 degrees, then composited at the bottom center of the dial, offset by the "half-width" of the arrow (actually 22 pixels rather than 25 as the bottom of middle of the arrow was not truly centered)
WARNING; Error Error.
+distort will generate a 'layer' image with offsets so as to keep the 'center of rotation' fixed on the virtual canvas. That is at 22,391. However -composite only uses geometry offsets!!! and ignore virtual canvas information completely!! See
Composite Geometry vs Layer Offsets.
basically if you try a rotate of say
-30 you would have got a very wrong result!
In summery DO NOT MIX THE TWO.
Either compose non-layer images with geometryt, or use layering methods to preserve virtual canvas offsets.
So lets modify the SRT distort to transplate the arrow to the correct 'center' of the half-circle. And layer the image together correctly...
Code: Select all
convert arrow.gif -virtual-pixel transparent \
+distort SRT "24.5,391 1.0 -30.0 350,350" -trim \
dial.gif +swap -background none -layers merge +repage \
arrow_dial-30.gif
The first coordinate 24.5,391 is the point in the arrow to rotate, while the 350,350 sets the position on the virtual canvas to position that 'center of rotation' (relative to the 'dial' image). The use of +distort ensures the output image is the 'best fit' offset layer image needed to hold the ALL of the arrow image (including the transparent corner pixels
The 1.0 is the scale factor (needed when setting a destination coordinate for the 'center')
while the -30.0 is the angle (rotate left this time) -trim is used to cut off excess corners in the rotated arrow. The dial is inserted before it and the two images 'layer merged' together.
Note as the 'arrow' does not always 'fit' into the 'dial' image (especially at -90, 0, and +90 angles, and along the bottom) the 'merge' will enlarge the resulting image appropriately to ensure none of the layered images are 'clipped'. You may not want the resulting image to change size, so you may want to 'scale' the arrow (adjusting the 1.0 in the above, or use
-flatten instead of
-layers merge to 'clip' the overlay to the base 'dial' image.
You may like to read up on distort coordinates...
http://www.imagemagick.org/Usage/distor ... oordinates