Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Ruby wrapping around gphoto2 C library
C Ruby

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
docs
ext
.gitignore
.manifest
CHANGELOG.rdoc
LICENSE
README.rdoc
Rakefile
example.rb
gphoto4ruby.gemspec

README.rdoc

GPhoto4Ruby

Summary

GPhoto4Ruby is Ruby wrapping around gphoto2 C library (See gphoto.org for more information on libgphoto2 and gphoto2). It maps a digital camera to Ruby object and allows operating it by calling object methods.

c = GPhoto2::Camera.new
c[:exptime] = "0.010" # you can list values with c[:exptime, :all]
c["f-number"] = "f/4.5"
c.capture

Installation

  • First of all you'll need the original gphoto2 C library installed. For installation instructions goto gphoto.org.

  • On Ubuntu 8.04 it is:

    sudo apt-get install gphoto2 libgphoto2-2-dev
  • On Mac OS X gphoto2 is installed through DarwinPorts

  • You can install GPhoto4Ruby gem from GitHub or from RubyForge. Use one of the following lines depending on your preferences:

    sudo gem install lonelyelk-gphoto4ruby --source http://gems.github.com

    or

    sudo gem install gphoto4ruby
  • Connect your digital camera through usb, locate example.rb file and run:

    ruby example.rb
  • NOTE! On Mac OS X there is a process you need to kill before using gphoto2. You can find more information on this at gphoto.org

Usage

After installation of this gem rdocs are generated for you. Or you can generate it manually with:

rake rdoc

Ruby file example.rb is installed along with this gem. All examples are tested on Kubuntu 8.04 and Mac OS X 10.4.11 with digital camera Nikon DSC D80 connected through usb in PTP mode.

example.rb:

require "rubygems"
require "gphoto4ruby"

ports = GPhoto2::Camera.ports
if ports.any?
    puts ports.length.to_s + "cameras connected"
    cams = []
    ports.each do |port|
        c = GPhoto2::Camera.new(port)
        puts "camera in port: " + port
        c.config.each do |key, value|
            puts key + " value is: " + value.to_s
            puts "values available are: " + c[key, :all].inspect
        end
        cams.push c
    end

    # capture image
    cams.first.capture

    # now camera virtual path is in the folder with images
    # list image file names
    puts "files on camera: " + cams.first.files.inspect

    # just an example of camera browsing
    puts "some folder stuff: " + cams.first.folder_up.subfolders.inspect

    # save preview of captured image in the current directory on hard drive
    cams.first.capture.save :type => :preview, :new_name => "PREVIEW.JPG"

    # save captured file in the current directory on hard drive and delete
    # it from camera
    cams.first.capture.save.delete

    # to capture image with all attached cameras simultaneously use:
    cams.each_index do |index|
        if index < cams.length - 1
            fork {cams[index].capture; exit!}
        else
            cams[index].capture
        end
    end
end

Contact

neq4 company

neq4.com

Sergey Kruk

sergey.kruk@gmail.com

Something went wrong with that request. Please try again.