Skip to content

Instantly share code, notes, and snippets.

@soramugi

soramugi/feedgif.rb

Last active Dec 22, 2015
Embed
What would you like to do?
feedからurlにアクセスしてスクリーンショット撮ってgif作成するやつ
#!/usr/bin/env ruby
require 'open-uri'
require "kconv"
require 'rss'
require 'capybara-webkit'
require 'RMagick'
uri = URI.parse('http://soramugi.tumblr.com/rss')
rss = RSS::Parser.parse(uri.read)
FileUtils.mkdir_p('files')
browser = Capybara::Webkit::Driver.new('web_capture').browser
rss.items.each_with_index do |item,i|
browser.visit item.link
browser.render("files/#{i}.jpg", 1280, 650)
end
rgb = Magick::ImageList.new(*Dir.glob("files/*"))
FileUtils.mkdir_p('resize')
rgb.each_with_index do |r,i|
r.crop(r.columns/2-612/2,0,612,612).write("resize/#{i}.jpg")
end
rgb = Magick::ImageList.new(*Dir.glob("resize/*"))
FileUtils.mkdir_p('gif')
rgb.iterations = 0
rgb.each_with_index do |r,i|
r.delay = 50
end
rgb.write('gif/animation.gif')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.