Upgrade to Pro — share decks privately, control downloads, hide ads and more …

The Pragmatic Animated GIF in Ruby (a RubyConf 2013 lightning talk)

The Pragmatic Animated GIF in Ruby (a RubyConf 2013 lightning talk)

one of lightning talks at RubyConf 2013, Miami Beach, FL, US
9th Nov, 2013

Shimpei Makimoto

November 09, 2013
Tweet

More Decks by Shimpei Makimoto

Other Decks in Technology

Transcript

  1. class GifAnime < Sinatra::Base get "/" do haml :index end

    post "/" do begin files = params[:files].map {|file| file[:tempfile] } rescue halt 401, "401: invalid parameters, maybe\n" end begin image = Magick::ImageList.new(*files.map(&:path)) rescue halt 405, "405: invalid image files, maybe\n" end content_type "image/gif" tempfile = Pathname.new(Tempfile.new(["", ".gif"])) image.write(tempfile) tempfile.read end end
  2. ...

  3. describe "sample.html", type: :feature do it "shows one message and

    toggles by the button", js: true do visit '/sample.html' page.should have_css(".contents div", count: 1) page.should have_css ".en" click_button "Change" page.should have_css(".contents div", count: 1) page.should have_css ".ja" click_button "Change" page.should have_css(".contents div", count: 1) page.should have_css ".kr" click_button "Change" page.should have_css(".contents div", count: 1) page.should have_css ".km" click_button "Change" page.should have_css(".contents div", count: 1) page.should have_css ".en" end end
  4. require "gifanime" class ScreenRecorder attr_accessor :gifanime, :tmpdir def initialize(output) @gifanime

    = Gifanime.new(output, delay: 40) @tmpdir = Dir.mktmpdir end def add(page) file = "#{tmpdir}/#{gifanime.frames.size}.gif" page.save_screenshot(file) gifanime.add(file) end def generate! gifanime.generate! end end
  5. describe "sample.html", type: :feature do before(:all) do @rec = ScreenRecorder.new("sample.gif")

    end after(:all) do @rec.generate! end it "shows one message and toggles by the button", js: true do visit '/sample.html' @rec.add(page) page.should have_css(".contents div", count: 1) page.should have_css ".en" click_button "Change" @rec.add(page) # ... end end
  6. Wrap up • Gif anime is almost good. • Gif

    anime is easily to make. • Gif anime is (sometimes) useful.
  7. Shimpei Makimoto (@makimoto) One of RubyConf 2013 Lightning Talks Thank

    you. The Pragmatic Animated GIF in Ruby ϧϏʔʹΑΔ࣮ફతͳδϑΞχϝ