Created
July 20, 2011 05:42
-
-
Save tatsuru/1094413 to your computer and use it in GitHub Desktop.
Generate divided gif animation for Thumblr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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