Skip to content

Instantly share code, notes, and snippets.

@troelskn
Created April 25, 2024 18:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save troelskn/d26adb9d36b154255fd1f9b17f5957e3 to your computer and use it in GitHub Desktop.
Save troelskn/d26adb9d36b154255fd1f9b17f5957e3 to your computer and use it in GitHub Desktop.
Combine multiple files into an animated gif with ruby-vips
require 'vips'
images = Dir["input-*.png"].map { |file| Vips::Image.new_from_file(file) }
combined = Vips::Image.arrayjoin(images, across: 1)
buffer = combined.gifsave_buffer(page_height: images.first.height)
gif_image = Vips::Image.new_from_buffer(buffer, "", n: images.length)
gif_image = gif_image.mutate do |y|
y.set!("delay", images.length.times.map { 1000 }) # time is in ms
end
gif_image.gifsave("animation.gif")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment