gphoto4ruby icon indicating copy to clipboard operation
gphoto4ruby copied to clipboard

Ruby wrapping around gphoto2 C library

= GPhoto4Ruby

== Summary

GPhoto4Ruby is Ruby wrapping around gphoto2 C library (See http://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 http://gphoto.org.

  • 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:

    GPhoto2::LIBGPHOTO2_VERSION

  • 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 http://gphoto.org

  • 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.

== 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-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.

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["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 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

end

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

== Contact

neq4 company:: http://neq4.com Sergey Kruk:: [email protected]