Am I looking for the most efficient way to stitch multiple images together in ImageMagick on top of a background image so that the spacing / indent between overlays is consistent?
I explored the use of + append, convert -composite and convert by merging -page and -layers.
The following command (convert-compposite) works, but requires a preliminary image size calculation to indicate absolute offsets. Indeed, I want a 10-pixel gap between the end of the FIRST layer image and the beginning of the second layered image, but the only way I can see to achieve this is to specify the absolute offset from the upper left corner of the canvas.
convert \ background.jpg \ first.jpg -gravity Northwest -geometry +10+10 -composite \ second.jpg -geometry +300+10 -composite \ third.jpg -geometry +590+10 -composite \ output.jpg
I'm looking for a kind of operator, so that the horizontal offset can be interpreted relative to the "last" image in the layer, so instead of specifying +300+10 for the second image and +590+10 for the third, I can somehow specify the offset +10+10 .
I thought gravity would allow me to achieve this ( -gravity Northwest ), in the same way as float: left; works in CSS positioning, but it is not.
I also had some success with the following:
convert \ -page +10+10 first.jpg \ -page +300+10 second.jpg \ -page +590+10 third.jpg \ -background transparent \ -layers merge \ layered.png convert background.jpg layered.png -gravity Center -composite output.jpg
Both methods described above require a preliminary calculation of the absolute displacements, which is a little painful. Is there a better way to do this?
Przemek Kujonewicz
source share