• Stars
    star
    15
  • Rank 1,327,357 (Top 27 %)
  • Language
    Crystal
  • License
    MIT License
  • Created almost 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Crystal shard wrapping libgphoto2

gphoto2.cr CI Releases License

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

Installation

Prerequisites

  • Crystal: ~> 1.11
  • libgphoto2: >= 2.5.2
  • libgphoto2_port: >= 0.10.1

To install the latest libgphoto2, you can use homebrew or apt-get, depending on the platform:

Mac OS X

$ brew install libgphoto2

Debian/Ubuntu

$ apt-get install libgphoto2-6 libgphoto2-dev libgphoto2-port12

Shard

Add this to your application's shard.yml:

dependencies:
  gphoto2:
    github: Sija/gphoto2.cr

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

# ...or use `#autorelease` on any `Camera` instance
camera.autorelease do
  # ...
end

# check camera abilities (see `GPhoto2::CameraOperation`)
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"

# compare the current configuration value
camera[:whitebalance] == "Automatic"
camera[:whitebalance] == :automatic
# => true

# list valid choices of a configuration option
camera[:whitebalance].as_radio.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"

# set radio widget value to first matching option
camera[:imageformat] = /Medium(.+?)JPEG/i

# 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" })

# ...do all of above while preserving camera original configuration
camera.preserving_config do
  # ...
end

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

# generate a zip file
folder.to_zip_file # => #<File:/tmp/camera.fs-[...].zip (closed)>

# 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/. Documentation can be generated using crystal doc task or browsed online.

Development

Enable debug mode by passing DEBUG=1 env variable:

DEBUG=1 crystal examples/list_cameras.cr

Run specs with:

crystal spec

Contributing

  1. Fork it (https://github.com/Sija/gphoto2.cr/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Thanks! 🎉

  • The gphoto2 developers for building such an awesome tool
  • @zaeleus for the ffi-gphoto2 gem, on which this library is heavily inspired

Contributors

  • @Sija Sijawusz Pur Rahnama - creator, maintainer

More Repositories

1

garb

A Ruby wrapper for the Google Analytics API
Ruby
147
star
2

raven.cr

Raven is a Crystal client for Sentry
Crystal
120
star
3

debug.cr

Debug macro for Crystal
Crystal
92
star
4

ipaddress.cr

A Crystal library to handle IPv4 and IPv6 addresses in a modern and productive way.
Crystal
43
star
5

retriable.cr

Retriable.cr is a simple DSL to retry failed code blocks
Crystal
38
star
6

any_hash.cr

Better JSON::Any for Crystal
Crystal
33
star
7

blurhash.cr

A pure Crystal implementation of BlurHash algorithm
Crystal
22
star
8

backtracer.cr

Crystal shard aiming to assist with parsing backtraces into a structured form.
Crystal
16
star
9

ksuid.cr

Crystal implementation of K-Sortable Globally Unique IDs
Crystal
16
star
10

crystal-dash-docset

Dash docset generator for Crystal
Shell
16
star
11

climate.cr

Tiny tool to make your CLI output 🌈 coloured
Crystal
14
star
12

serialport.cr

Crystal bindings for libserialport: cross-platform library for accessing serial ports.
Crystal
12
star
13

base62.cr

Base62 encoder/decoder for Crystal
Crystal
10
star
14

crystal-environment

Crystal::Environment
Crystal
7
star
15

gphoto2-web

Web API for libgphoto2
Crystal
6
star
16

gitbook2pdf

CLI utility to turn a published GitBook website into a collection of PDFs for offline reading
JavaScript
3
star
17

Gizmo

Quick'n'easy file based content management system
PHP
2
star
18

jsonl.cr

Crystal shard for handling JSONL (JSON Lines) parsing
Crystal
1
star
19

Sija

1
star
20

coffeeshop

Unfinished Coffee powered, Express based framework for Node.js
CoffeeScript
1
star
21

kPilot.w3

Web backend for kPilot Konnekt IM plugin.
PHP
1
star
22

markdown

PSR-0 compliant Markdown library
PHP
1
star
23

seedling

Rails 3 plugin for a database-independent YAML seeds import/export.
Ruby
1
star
24

MazeSolver

Maze solver written in PHP 5.
PHP
1
star
25

kZmieniacz

kZmieniacz to wtyczka dla komunikatora Konnekt pozwalająca zmieniać status opisowy jednocześnie we wszystkich wykorzystywanych sieciach.
C++
1
star
26

photoindex

Ancient, self-contained php gallery script.
PHP
1
star
27

resque-dry

Ruby
1
star
28

swift

Never finished C++ templating engine.
C++
1
star
29

kulturadaru

PHP
1
star
30

smartypants

PSR-0 compliant Smartypants library
PHP
1
star
31

kAway

Away system for the Konnekt IM
C++
1
star
32

git-rewrite-author

CLI tool for rewriting author/committer history of a git repository
Crystal
1
star
33

QRKit

QR Reader in Objective C ported from zxing
C++
1
star
34

thumb-cutter

Blazingly fast thumb cutting and image juggling middleware for any node/express.js kitchen sink
JavaScript
1
star
35

sunspot_resque

Sunspot-Resque Session Proxy
Ruby
1
star
36

jquery.clamp

JavaScript with CSS "overflow: ellipsis" line clamping, as jQuery plugin and standalone AMD module
CoffeeScript
1
star