If the image has no transparency convert src.png mask.png -alpha off -compose copy_opacity -composite result.png If the image has some transparency compose Dst_In \( mask.png -alpha copy \) src.png -alpha Set -composite PNG32:result.png I didn't figure out how to keep colors