-
-
Save robmiller/9814585 to your computer and use it in GitHub Desktop.
Take a webcam shot and save it in the pictures directory. Depends on tenderlove's av_capture: `gem install av_capture`
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
#!/usr/bin/env ruby | |
require 'av_capture' | |
require 'pathname' | |
session = AVCapture::Session.new | |
dev = AVCapture.devices.find(&:video?) | |
dir = Pathname(File.expand_path("~/Pictures/av")) | |
Dir.mkdir(dir) unless dir.exist? | |
# If we've got an argument, use it as a filename suffix | |
suffix = "_#{ARGV[0]}" || "" | |
filename = dir + "#{Time.now.strftime('%Y-%m-%d-%H%M%S')}#{suffix}.jpg" | |
session.run_with(dev) do |connection| | |
# The camera -- or my MBP's iSight, anyway -- seems to need half a second | |
# or so to focus and set the correct exposure | |
sleep 0.5 | |
File.open(filename, "w") { |f| f.write connection.capture } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment