Giter VIP home page Giter VIP logo

ffi-gphoto2's Introduction

ffi-gphoto2

Gem Version Build Status

ffi-gphoto2 provides an FFI for common functions in libgphoto2. It also includes a facade to interact with the library in a more idiomatic Ruby way.

Installation

Prerequisites

  • Ruby >= 1.9
  • libgphoto2 >= 2.5.2
  • libgphoto2_port >= 0.10.1

Gem

$ gem install ffi-gphoto2

Usage

require 'gphoto2'

# list available cameras
cameras = GPhoto2::Camera.all
# => [#<GPhoto2::Camera>, ...]

# list found cameras by model and port path
cameras.map { |c| [c.model, c.port] }
# => [['Nikon DSC D5100 (PTP mode)', 'usb:250,006'], ...]

# use the first camera
camera = cameras.first

# ...or more conveniently
camera = GPhoto2::Camera.first

# search by model name
camera = GPhoto2::Camera.where(model: /nikon/i).first

# the above examples require the camera be manually closed when done
camera.close

# pass a block to automatically close the camera
GPhoto2::Camera.first do |camera|
  # ...
end

# check camera abilities (see `FFI::GPhoto2::CameraOperation.symbols`)
camera.can? :capture_image
# => true

# list camera configuration names
camera.config.keys
# => ['autofocusdrive', 'manualfocusdrive', 'controlmode', ...]

# read the current configuration value of an option
camera['expprogram'].value
# => "M"
camera['whitebalance'].value
# => "Automatic"

# list valid choices of a configuration option
camera['whitebalance'].choices
# => ["Automatic", "Daylight", "Fluorescent", "Tungsten", ...]

# check if the configuration has changed
camera.dirty?
# => false

# change camera configuration
camera['iso'] = 800
camera['f-number'] = 'f/4.5'
camera['shutterspeed2'] = '1/30'

# check if the configuration has changed
camera.dirty?
# => true

# apply the new configuration to the device
camera.save

# alternatively, update the camera configuration in one go
camera.update(iso: 200, shutterspeed2: '1/60', 'f-number' => 'f/1.8')

# take a photo
file = camera.capture

# ...and save it to the current working directory
file.save

# ...or to a specific pathname
file.save('/tmp/out.jpg')

# traverse the camera filesystem
folder = camera/'store_00010001/DCIM/100D5100'

# list files
files = folder.files
folder.files.map(&:name)
# => ["DSC_0001.JPG", "DSC_0002.JPG", ...]

# copy a file from the camera
file = files.first
file.save

# ...and then delete it from the camera
file.delete

More examples can be found in examples/. YARD documentation can be generated using the rake yard task or browsed online.

ffi-gphoto2's People

Contributors

zaeleus avatar sija avatar chunkerchunker avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.