1
votes

I'd like to use "convert" (or whatever) from Imagemagick to combine two different sized images. I'd like them to be aligned at the bottom left corners. For example, I have two images:

trans_alpha.png (a transparent 42x37 blank image) and shadow.png (a 68x23 image, which I want overlaid on trans_alpha.png aligned at the bottom left)

The result I'd like would be a 68x37 image, NOTE these sizes are examples only, I don't want to put the size into the command line, I just want to use the sizes from the input images.

I have tried a lot of combinations without success:

Attempt no. 776 (close, but aligned to top left, not bottom left)..:

convert trans_alpha.png -background none shadow.png -gravity SouthWest -layers merge  +repage result.png

Attempt no. 841 (aligned correctly, but result image isn't wide enough)...

convert trans_alpha.png shadow.png -gravity SouthWest -composite result.png

Hopefully that makes sense. Thanks,

Paul

3

3 Answers

2
votes

In answer to my own question (courtesy of the clever people on www.imagemagick.org)

convert \
  trans_alpha.png shadow.png \
 -flip \
 -background none \
 -mosaic \
 -flip \
  result.png
1
votes

Imagemagick includes many useful transformations, but occasionally still it lacks the one you need. Since your original images are PNG lossless bitmaps, you can convert both to long-form PBM or a related format like long-form PPM. The advantage of these forms is that they represent the entire image, pixel by pixel, in plain text, which one can write a program -- usually a fairly short program -- to process any way one likes. As storage formats, PBM and PPM are egregiously inefficient, but they are likewise egregiously easy to manipulate, and that's what you want.

The pbm(5) manpage (available for example on Debian/Ubuntu systems in the netpbm package) is well written and explains the process clearly.

0
votes

I am unable to test at the moment but you can use -page with layers so something like this might work but you may need to calculate the Y offset:

convert \
   trans_alpha.png \
  -background none \
   shadow.png \
  -page +0+10 \
  -layers merge \
  +repage \
   result.png

You may not need the -background none