Skip to content
Ruby wrapping around gphoto2 C library
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.




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

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


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

  • On (k)ubuntu it is:

    sudo apt-get install libgphoto2-2-dev
  • On Mac OS X gphoto2 is installed through DarwinPorts. Or you can install it from source

  • You can install GPhoto4Ruby gem from GemCutter or from RubyForge:

    sudo gem install gphoto4ruby
  • If you installed libgphoto2 from source you might want to use custom paths

    sudo gem install -i gphoto4ruby -- --with-opt-dir=/opt-custom-prefix
  • If you have more than one version of libgphoto2 installed and you want to specify which one to use:

    sudo gem install -i gphoto4ruby -- --with-gphoto2-dir=/custom-prefix --with-dldflags="-Wl,-rpath,/custom-prefix/lib"

    Following code will tell you, which version of libgphoto2 you use:

  • 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

  • NOTE! For unknown reason after upgrade to Kubuntu 9.10 Canon EOS 450D stopped capturing images. It just hangs in infinit loop. Both with my gem and with command line gphoto2 tool. Even for (lib)gphoto2 2.4.7. You can change configuration though. And with kubuntu 9.04 everything is ok.


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-9.04 and Mac OS X 10.4.11 with digital camera Nikon DSC D80 connected through usb in PTP mode and Canon EOS 450D.


require "rubygems"
require "gphoto4ruby"

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

    # capture image

    # 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 :type => :preview, :new_name => "PREVIEW.JPG"

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

On supported systems, instanciating a camera will start a thread that 
prevents the camera from posering off automatically.


neq4 company

Sergey Kruk

You can’t perform that action at this time.