rs13 wrote:Thank you all for your prompt responses.
Anthony, you are correct, I have a specific point in the destination image (image B) in mind and it is not the center point.
Also, I am doing the positioning of image A onto the destination image (image B) on the fly so I will not know A's dimensions which will be changing constantly.
All I need to do is to position center pixel of image A onto specific offset in the image B.
Any ideas?
Assuming that you are wanting B on top of A and the 'handle point' in B is 12,13
then you can do the following.
convert A.png -set page '-%[fx:int(w/2)]-%[fx:int(h/2)]' \
-page -12-13 B.png \
-background none -layers merge +repage \
result.png
The
-set page sets the virtual offset so the center of the image A is at 0,0.
The
-page then sets the page of the following image read/create so that B's handle is a 0,0
-layers merge then overlays A on a canvas, then B onto that with the given offsets while handling 'negative' offsets appropriately. Finally
+repage removes the negative offset from the result.
NOTE this assumes that B is completely inside A's bounds. If this may not be that case then you may need to use -set to first save A's starting dimensions or center so you can restore the results.
This only does integer positions. If you want sub-pixel positions you will need to use distort SRT for positioning, and that can take FX escapes directly!
ASIDE: while
-set page works,
-set geometry does not seem to work!
Aside... THIS FAILS!!!!!
Here is a another variation of doing the math, But reading both images in first (easier scripting) and using a globle artifact which is then assigne to just one one. In this case only the overlay (B) is moved, so flatten can be used to limit output to just the first image area.
convert A.png B.png -set option:myoffset '+%[fx:int(u.w/2)-12]+%[fx:int(u.h/2)-13]' \
\( +clone -set page '%[myoffset]' \) +swap +delete \
-background none -flatten result.png
THIS FAILS!!!!! Because of the way
-set does not have access to ALL the images. That is the u.h is not from A, but from the last image the expression is applied to B so the center offset saved into the global variable is B, not A
This is a bug! Arrggghhhh....
Set really needs access to all images. But to do that it will need to be removed from "mogrify"