Execute this ImageMagick command in a Rails app
New here? Learn about Bountify and follow @bountify to get notified of new bounties! x

Here is the ImageMagick command I'd like executed in my Rails app (takes a GIF animation and overlays a transparent gif watermark):

convert background-animation.gif -coalesce -draw 'image over 0,0 0,0 "transparent-watermark.png"' -layers Optimize final.gif

However, it should work with remote files. The "convert" command doesn't work on remote images, but check out a solution here.

Finally, it should save the output to the public folder.

Should be straightforward! Please let me know if you have any questions.

awarded to poserg

Crowdsource coding tasks.

1 Solution

Winning solution

Check this. Just enter your path to background-animation.gif in bg_url.

require 'rubygems'
require 'RMagick'
require "open-uri"

bg_url =

image = Magick::ImageList.new

urlimage = open(bg_url)
image.from_blob(urlimage.read)

watermark = Magick::ImageList.new("transparent-watermark.png")

result = Magick::ImageList.new
image.each_with_index do |frame, index|
result << frame.composite(watermark, 0, 0, Magick::OverCompositeOp)
end

result.optimize_layers(Magick::OptimizeLayer).write("final_out.gif")