Class: MagickCam
- Inherits:
-
Object
- Object
- MagickCam
- Defined in:
- lib/magickcam.rb
Instance Method Summary collapse
-
#initialize ⇒ MagickCam
constructor
A new instance of MagickCam.
- #snapshot(filename = 'webcam.jpg') ⇒ Object
Constructor Details
#initialize ⇒ MagickCam
Returns a new instance of MagickCam.
182 183 184 |
# File 'lib/magickcam.rb', line 182 def initialize() @capture = Webcam.new end |
Instance Method Details
#snapshot(filename = 'webcam.jpg') ⇒ Object
186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/magickcam.rb', line 186 def snapshot(filename='webcam.jpg') image = @capture.grab width, height = image.size[:width], image.size[:height] img = Magick::Image.new width, height image.data.unpack("C*").each_slice(3).each_slice(width).with_index do |r, i| q = r.map {|b, g, r| Magick::Pixel.new r * 256, g * 256, b * 256, 0} img.store_pixels(0, i, width, 1, q) end img.format = 'jpg' puts 'saving ' + filename img.write filename end |