Skip to content

Instantly share code, notes, and snippets.

@tatsuru
Created July 20, 2011 05:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tatsuru/1094413 to your computer and use it in GitHub Desktop.
Save tatsuru/1094413 to your computer and use it in GitHub Desktop.
Generate divided gif animation for Thumblr
#!/usr/bin/env ruby
require 'rubygems'
require 'RMagick'
def split(src, n)
width = src.columns
height = src.rows
crop_list = []
n.times{ |i|
y_start = height/n * i
n.times{ |j|
x_start = width/n * j
crop_list.push( src.crop(x_start, y_start, width/n, height/n, true) )
}
}
crop_list
end
def create_cropgif(src, n=2)
sep_list = nil
sep_list = []
src.each do |img|
sep_list.push(split(img, n))
end
sep_list.transpose
end
if $0 == __FILE__
require 'optparse'
return if ARGV.length != 2
src = ARGV[0]
srcimg = Magick::ImageList.new(src)
n = ARGV[1].to_i
dsts = create_cropgif( srcimg, n )
(n*n).times do |i|
img = Magick::ImageList.new
dsts[i].each { |d| img.push(d) }
img.delay = srcimg.delay
p img.delay
img.write( File.dirname(src) + '/' + File.basename(src, '.gif') + "#{i}.gif")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment