ImageMagick: combine two images with transparency at the border

0

I have two JPGs one big.jpg and the other small.jpg. I want to extract a region region.jpg of big.jpg of the same size as small.jpg and merge region.jpg and small.jpg into a result.jpg. result.jpg is equal to small.jpg, except at the 16 pixels boundary where it gets more and more similar to region.jpg.

Using ImageMagick, I have done this in two steps, making a semitransparent PNG first:

convert -compress None small.jpg -channel A -virtual-pixel transparent -morphology Distance Euclidean:4,16! semitransparent.png
convert -compress None big.jpg -crop wxh+x+y semitransparent.png -composite result.jpg

Is there any way of doing this in a single step, without generating the intermediate PNG? I tried this:

convert -compress None big.jpg -crop wxh+x+y small.jpg -channel A -virtual-pixel transparent -morphology Distance Euclidean:4,16! -composite result.jpg

But this is not quite the same: the semitransparent layer does not end up really transparent at the edge.

I am a total newbie to ImageMagick (what a complex piece of software!), any suggestions would be appreciated.

EDIT

I'm adding files big.jpg and small.jpg to play with, together with result.jpg that comes out of the 2-line solution, and result2.jpg that comes out of the oneliner. The -crop I used was 200x160+160+80:

big.jpg big.jpg

small.jpg small.jpg

result.jpg result.jpg (2 line solution)

result2.jpg result2.jpg (oneliner)

Luis A. Florit

Posted 2019-02-13T20:22:24.893

Reputation: 151

Answers

1

Sorry, but I just found the answer. Simply add -compose atop before the -composite:

convert -compress None big.jpg -crop 200x160+160+80 small.jpg \
  -channel A -virtual-pixel transparent \
  -morphology Distance Euclidean:4,16! \
  -compose atop -composite result.jpg

Luis A. Florit

Posted 2019-02-13T20:22:24.893

Reputation: 151