Created
December 23, 2010 04:53
-
-
Save kei-s/752581 to your computer and use it in GitHub Desktop.
This file contains 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
# vim:fileencoding=utf-8 | |
require 'cgi' | |
require 'rubygems' | |
require 'rmagick' | |
require 'haml' | |
module Jigokuno | |
class Aggregator | |
def initialize(directory) | |
@directory = directory | |
end | |
def create_view | |
haml =<<HAML | |
%html | |
%head | |
%title 忙しい人のための『地獄のミサワの「女に惚れさす名言集」』 | |
%body | |
- Dir.glob("#{@directory}/*_*.gif").each do |file| | |
%img{:src => CGI.escape(File.basename(file))} | |
HAML | |
engine = Haml::Engine.new(haml) | |
open('%s/index.html' % @directory,'w') do |file| | |
file.puts engine.render | |
end | |
end | |
def convert | |
all = Magick::ImageList.new | |
Dir.glob('images/*.gif').group_by {|file| | |
File.basename(file,".*").split('_').last | |
}.each{|key,files| | |
list = Magick::ImageList.new | |
files.each{|file| | |
image = Magick::Image.read(file)[0].resize(240,320) | |
if image.alpha? | |
image.matte = false | |
end | |
all << image | |
list << image | |
} | |
if files.size > 2 | |
yield list, '%s/%s_%s.gif' % [@directory,key,files.size] | |
end | |
} | |
yield all, '%s/all.gif' % @directory | |
end | |
end | |
end |
This file contains 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
# vim:fileencoding=utf-8 | |
require_relative 'aggregator' | |
directory = "animate" | |
Dir.mkdir directory unless File.exist? directory | |
aggregator = Jigokuno::Aggregator.new(directory) | |
aggregator.convert do |imageList,file| | |
puts file | |
imageList.iterations = 0 | |
imageList.write(file) | |
end | |
aggregator.create_view |
This file contains 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
# vim:fileencoding=utf-8 | |
require_relative 'aggregator' | |
directory = "average" | |
Dir.mkdir directory unless File.exist? directory | |
aggregator = Jigokuno::Aggregator.new(directory) | |
aggregator.convert do |imageList,file| | |
puts file | |
imageList.average.write(file) | |
end | |
aggregator.create_view |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment