Skip to content

Latest commit

 

History

History
204 lines (140 loc) · 6.75 KB

README.md

File metadata and controls

204 lines (140 loc) · 6.75 KB

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

Know issue

This package isn't compatible with Node.js 13 and higher version. @tsed/gphoto2-driver use ref-array-napi which have a bug with some node.js version related here.

The possible solutions would be:

  • Find a way not to use ref-array-napi to manipulate C++ Array in Node.js,
  • That the author of the module finds a solution to correct the problem,
  • Redevelop the driver directly with NAPI.

Obviously any help is welcome to move the project forward :)

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

Linux / Mac OS Intel

brew install libgphoto2

// or
apt-get install libgphoto2-dev

// then
npm install @tsed/gphoto2-driver

Mac OS M1 (Rosetta)

On Mac M1 chipset, you have to install homebrew with the x64 architecture:

/usr/sbin/softwareupdate --install-rosetta

arch -x86_64 zsh
mkdir ~/Downloads/homebrew
curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew
sudo mv ~/Downloads/homebrew /usr/local/homebrew
sudo chmod 755 /usr/local/homebrew/bin/brew
arch -x86_64 /usr/local/homebrew/bin/brew install libgphoto2

arch -arm64 zsh

Create brew alias. Edit your ~/.zshrc file and add the followings lines:

export PATH=$HOME/bin:/usr/local/bin:$PATH

alias xbrew='arch -x86_64 /usr/local/homebrew/bin/brew'

Now you can run brew with x64 architecture by usin xbrew alias:

xbrew install libgphoto2

You also need to install Node.js with the appropriate:

arch -x86_64 zsh
nvm install v12
nvm use v12
npm install @tsed/gphoto2-driver
arch -arm64 zsh

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 gphoto2

// Linux
sudo apt install gphoto2

Demo

Run:

yarn start

Then open the browser on http://localhost:3000

The demo code source is inside packages/client and packages/server.

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.