Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
shuffle_animation_gif.rb
# -*- coding: utf-8 -*-
require 'rubygems'
require 'RMagick'
filename = ARGV.first
unless filename
warn "usage: #{$0} <ANIMATION GIF FILE>"
exit 1
end
source = Magick::ImageList.new(filename)
dest = Magick::ImageList.new
source.coalesce.sort_by{ rand }.each{ |frame|
dest.push frame
}
dest.delay = source.delay
dest.iterations = 0
dest.optimize_layers(Magick::OptimizeTransLayer).deconstruct.write("out.gif")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment