class ImageProcessing::Vips::Processor
def composite(overlay, _mode = nil, mode: "over", gravity: "north-west", offset: nil, **options)
Overlays the specified image over the current one. Supports specifying
def composite(overlay, _mode = nil, mode: "over", gravity: "north-west", offset: nil, **options) # if the mode argument is given, call the original Vips::Image#composite if _mode overlay = [overlay] unless overlay.is_a?(Array) overlay = overlay.map { |object| convert_to_image(object, "overlay") } return image.composite(overlay, _mode, **options) end overlay = convert_to_image(overlay, "overlay") # add alpha channel so that #gravity can use a transparent background overlay = overlay.add_alpha unless overlay.has_alpha? # apply offset with correct gravity and make remainder transparent if offset opposite_gravity = gravity.to_s.gsub(/\w+/, "north"=>"south", "south"=>"north", "east"=>"west", "west"=>"east") overlay = overlay.gravity(opposite_gravity, overlay.width + offset.first, overlay.height + offset.last) end # create image-sized transparent background and apply specified gravity overlay = overlay.gravity(gravity, image.width, image.height) # apply the composition image.composite(overlay, mode, **options) end