Skip to content

Instantly share code, notes, and snippets.

@hitode909
Created January 14, 2012 07:12
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hitode909/1610577 to your computer and use it in GitHub Desktop.
Save hitode909/1610577 to your computer and use it in GitHub Desktop.
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