Is it possible to create a GIF from input .png frames? #325
-
Is it possible to create a GIF from a series of .png input frames? This example is the best that I've so far found showing how to manipulate a gif using require "vips"
frame1 = Vips::Image.new_from_file "frame1.png"
frame2 = Vips::Image.new_from_file "frame2.png"
frames = [frame1, frame2]
new_image = Vips::Image.arrayjoin(frames, across: 1)
new_image = new_image.mutate do |x|
x.set_type! GObject::GINT_TYPE, "page-height", frame1.height * 2
end
new_image.magicksave("output.gif", format: "gif") Perhaps unsurprisingly, this outputs a file that is a single image showing the two input frames stacked upon each other, not an animated GIF. I'm hoping that there's a way to specify things like timing between frames. I know it's possible to do this with libraries like |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hi again, You've got it, just take the #!/usr/bin/ruby
require "vips"
frames = ARGV[1..].map do |filename|
Vips::Image.new_from_file filename, access: :sequential
end
image = Vips::Image.arrayjoin frames, across: 1
image = image.mutate do |x|
x.set_type! GObject::GINT_TYPE, "page-height", frames[0].height
x.set_type! Vips::ARRAY_INT_TYPE, "delay", [500, 1000]
end
image.write_to_file ARGV[0] Then:
The delays are in milliseconds. You can write animated webp too, of course. There are some more controls for the GIF writer: https://www.libvips.org/API/current/VipsForeignSave.html#vips-gifsave |
Beta Was this translation helpful? Give feedback.
Hi again,
You've got it, just take the
*2
off. I'd write it as:Then:
The delays are in milliseconds. You can write animated webp too, of course. There are some more controls for the GIF writer:
https://www.libvips.org/API/current/VipsForeignSave.h…