Created
July 12, 2013 22:17
-
-
Save mrpollo/5988297 to your computer and use it in GitHub Desktop.
create animated gifs aout of a lot of screencaptures for OSX ONLY
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
class Screengif | |
attr_reader :screencapture, :convert, :tempname, :delay, :times | |
def initialize args | |
@screencapture = '/usr/sbin/screencapture' | |
@convert = '/usr/local/bin/convert' | |
args.each do |k,v| | |
instance_variable_set("@#{k}", v) unless v.nil? | |
end | |
@tempname.gsub!("\n", '') | |
(1..@times).each do |i| | |
screencapture ( i == 1 ? @delay : 0.5), "#{@tempname}_#{i}.png" | |
makegif "#{@tempname}_#{i}.png" | |
end | |
animategif "#{@tempname}_*.gif" | |
cleanup | |
end | |
def screencapture delay, output | |
`#{@screencapture} -T #{delay} #{output}` | |
end | |
def makegif file | |
`#{@convert} #{file} #{file.gsub(/\.[a-z]{3,4}$/, '.gif')}` | |
end | |
def animategif files | |
`#{@convert} -delay 20 -loop 0 #{files} #{@tempname}_FINAL.gif` | |
end | |
def cleanup | |
(1..@times).each do |i| | |
`rm #{@tempname}_#{i}.png #{@tempname}_#{i}.gif` | |
end | |
end | |
end | |
Screengif.new :delay => 5, :times => 5, :tempname => `date +%s` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ruby screengif.rb