ImageMagick: Layering Images with convert -composite with gravity center

Piotr Tomasik picture Piotr Tomasik · Jan 27, 2012 · Viewed 10k times · Source

enter image description here

background

http://i.stack.imgur.com/wA2EL.png

overlay

composite -gravity center overlay.png  background.jpg  result1.jpg

http://i.stack.imgur.com/XgdA2.jpg

result1.jpg

convert -composite background.jpg overlay.png -gravity center result2.jpg

result2.jpg

convert -composite background.jpg -gravity center tool_marker.png  result3.jpg

result3.jpg

How can I achieve the results from result1 while using convert as the executable rather than composite?

Thanks!

Answer

Piotr Tomasik picture Piotr Tomasik · May 7, 2012

You can start by using the operators in the right order. That is set the 'settings' first. "Composite" command is 'read all settings then apply ONE operation, type of command (traditional UNIX) "Convert" is a 'do options as you see them', with MULTIPLE operations possible. (script-like command)

convert  background.jpg  tool_marker.png -geometry +50+50 -composite result4.jpg

Note the +50+50 is the location of the top-left corner of the 'tool_marker.png" image. You will need to subtract the 'pin-point' location in that image to get it to pin point in the right location.

Gravity Center (if given BEFORE the -composite operation that uses it), aligns the center of BOTH images.

convert background.jpg tool_marker.png -gravity center -composite result4.jpg