Skip to content

Is it possible to create a GIF from input .png frames? #325

Answered by jcupitt
GavinJoyce asked this question in Q&A
Discussion options

You must be logged in to vote

Hi again,

You've got it, just take the *2 off. I'd write it as:

#!/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:

$ vips invert ~/pics/k2.jpg x.jpg
$ ./mkgif.rb x.gif ~/pics/k2.jpg x.jpg 

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…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by GavinJoyce
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants