I have this imagemagick command which applies a mask to an image:
convert \( subject.jpg -resize "370x210^" -gravity Center -crop "370x210+0+0" \) \( mask.png -resize "370x210" -gravity "Center" \) -composite out.png
The image ends up with the desired dimensions, conserving aspect ratio. The mask ends up smaller than the target dimensions, but centered. This is all very well and exactly what I want. However, I would like whatever is outside the mask to be coloured (hiding the part of the image that is outside the mask).
This is the current result:
This is what I'm looking for:
(Notice the images are the same width and height, but the "sidebars" no longer appear on the bottom image. It the mask and the image had the same aspect ratio, there wouldn't be a difference between these two images.)
I've tried a lot of different things (compositing with an extra full sized white image, borders, frames, etc.) but I can't get the desired output, nor can I find a good example online. Any tips?
Fill the image mask up to the clipping border with the -draw color commands. This technique is very close to print's bleed & video's overscan.
Example
Given a mask of..
Define your mask's border-color that is the clipping boundary, and what color to fill with.
For this example, the border & color are black. Note I've added the missing -compose & -alpha, but that's localized to my example.
convert \
\( source.jpg -resize "370x210^" -gravity Center -crop "370x210+0+0" \) \
\( mask.png -resize "370x210" -gravity "Center" \
-bordercolor black \
-fill black \
-draw "color 10,10 filltoborder" \
\) \
-alpha Off -compose CopyOpacity -composite out.png
source.png
out.png