Created
April 25, 2024 18:34
-
-
Save troelskn/d26adb9d36b154255fd1f9b17f5957e3 to your computer and use it in GitHub Desktop.
Combine multiple files into an animated gif with ruby-vips
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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