Skip to content
production
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Ts.ED logo

Ts.ED GPhotoDriver2

Build & Release PR Welcome Coverage Status npm version semantic-release code style: prettier backers


Slack Β Β β€’Β Β  Twitter

A Node.js wrapper for libgphoto2 written in TypeScript. Useful for remote controlling of DSLRs and other digital cameras supported by gphoto2.

Features

  • Camera autodetection,
  • Take a picture/movie capture,
  • Take a preview,
  • Retrieve camera list,
  • Select camera,
  • Take a liveview from camera and get binary or base64 of each frame, or write it to file,
  • Display info about your camera (summary, about, manual).

Prerequisite

  • Node.js: 12
  • NPM: ~7.10.0
  • Nan: ~2.8.0
  • libgphoto2: ~2.5.x - via brew install libgphoto2, apt-get install libgphoto2-dev or download and build from http://www.gphoto.org/proj/libgphoto2/,
  • pkg-config | dpkg (used for dependency checking)
  • clang compiler

Note: This package cannot be used in front-end context (like webpack, browserify, etc...). You have to develop your own web server and expose your API.

Installation

After installing the dependencies, just install using:

brew install libgphoto2
// or
apt-get install libgphoto2-dev

// then
npm install @tsed/gphoto2-driver

Check if your camera is detected

GPhoto2 CLI can help you to know if your camera is correctly detected by the libphoto2 driver. It can help to determine if the the detection issue is related from the driver or from the Ts.ED GPhoto2 library.

Install the GPhoto2 CLI:

// MacOs
brew install libgphoto2
// Linux
sudo apt install gphoto2

Usage

Here an example with TypeScript (works also with pure javascript in Node.js):

import Path from "path";
import { CameraList, run } from "@tsed/gphoto2-driver";

run(() => {
  const cameraList = new CameraList().load();

  if (cameraList.size) {
    const camera = cameraList.getCamera(0);
    const cameraFile = camera.captureImage();

    cameraFile.save(path.join(__dirname, 'capture.jpeg'));
  }
}, {logLevel: 'debug'})

CameraFile

A lot of different API's of this library returns a CameraFile object.

This object does not contain the image, it is just a pointer to the file in camera's RAM.

You have several options to get your image:

  1. Use .save(filename) of .saveAsync(filename) methods, that will save the image to your filesystem.
  2. Use .getDataAndSizeAsync('binary' | 'base64') method, which returns following object:
{
  data: data, // Buffer for binary format and string for base64.
  size: size
}

Examples

Some examples are available in the packages/examples/src directory, when you have cloned or downloaded the complete project from github.

Checkout this project then run npm run install:examples && npm run develop and run node examples/camera.ts.

Contribute

Contributors and PR are welcome. Before, just read contributing guidelines here ;)

License

The MIT License (MIT)

Copyright (c) 2016 - 2021 Romain Lenzotti

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.