npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-camera

v1.1.0

Published

This `gphoto2` wrapper for Node.js enables you to capture images, bursts, timelapses or even video.

Downloads

20

Readme

node-camera

This rather complete Node wrapper for gphoto2*(required)* enables you to list all compatible cameras and their abilities, setup camera parameters, capture images, bursts, timelapses and even video, if supported.

1. Installation

1.1. Install prerequisities

As this package is a mere wrapper of the gphoto2's cli, you need to install that first:

a) MacOS

brew install gphoto2

b) Linux

sudo apt-get install gphoto2

c) Windows

Haven't tested it, so feel free to google instructions from somebody who has.

1.2. Install the npm package

After you have the dependencies installed, it's all easy-peasy lemon-squeezy from there:

yarn add node-camera

2. Getting started

import { Camera, Identificator } from "node-camera";

Camera.listCameras()
  .then(list => {
    if (list.length) {
      const CanonEOS7D = new Camera(list[0]);
      CanonEOS7D.identifyBy = Identificator.Model;
      CanonEOS7D.captureImage({
        forceOverwrite: true,
        filename: "./photo.%C"
      });
      setTimeout(
        () =>
          CanonEOS7D.captureImage(
            { forceOverwrite: true, interval: 3, filename: 'photo%03n.%C' },
            {
              onData: data => console.log("Received some logs: ", data.toString()),
              onError: error =>
                console.log("This was not supposed to happen: ", error.toString()),
              onClose: exitCode =>
                exitCode === 0
                  ? console.log("Do something now with the photos")
                  : console.log("This without an error usually means" +
                  " cancellation.")
            }
          ),
        5000
      );
      setTimeout(() => CanonEOS7D.stopCapture(), 15000);
    }
  })
  .catch(e => console.log(`error: ${e}`));

2.1. Notable stuff in the example

2.1.1 Non-concurrency

Noticed the timeouts? If you try to capture another image whilst a capture process is still running, you'll get an error. To prevent this, you either have to wait or kill the process by calling <CameraInstance>.stopCapture().

2.1.2 Identificators

At line

CanonEOS7D.identifyBy = Identificator.Model;

we specify that node-camera should search for camera with name Canon EOS 7D, whereas if we write

CanonEOS7D.identifyBy = Identificator.Port;

the program will try to connect camera with the specified port. Identification by model is enabled as default, so if you have one camera only, you don't have to do anything.

However, should you have two or more cameras of the same make and model, identification by port comes in handy as it enables you to distinguish between the cameras.

2.1.3 Filename

The filename option accepts %a, %A, %b, %B, %d, %H, %k, %I, %l, %j, %m, %M, %S, %y, %%, (see date(1)) and, in addition, %n for the number, %C for the filename suffix, %f for the filename without suffix, %F for the foldername, %: for the complete filename in lowercase.

Note that %: is still in alpha stage, and the actual character or syntax may still be changed. E.g. it might be possible to use %#f and %#C for lower case versions, and %^f and %^C for upper case versions.

%n is the only conversion specifier to accept a padding character and width: %03n will pad with zeros to width 3 (e.g. print the number 7 as “007”). Leaving out the padding character (e.g. %3n) will use an implementation specific default padding character which may or may not be suitable for use in file names.

3. API

3.1 Static methods

Camera.listCameras(): Promise<ConnectionParams>

getConfigurationTree(port: string): Promise<CommandResult>

Gets the whole configuration tree for the camera including current values and values that are possible to be set. This is useful e.g. for making a form to set up the camera.

3.2 Constructors

Camera(cameraParams: ConnectionParams): Camera

3.3 Instance methods

####burst({length: number, filename?: string}, callbacks?: Callbacks): void Captures multiple images for a specified time as quickly as possible.

captureImage(options: CaptureOptions, callbacks?: Callbacks): void

Captures image or images using provided options.

getConfig(propertyNames: string[]): Promise<CommandResult>

Gets a configuration property/properties value from the camera.

reset(): Promise<CommandResult>

Resets the camera's port.

####setConfig(properties: Record<string, any>): Promise<CommandResult> Sets configuration values.

stopCapture(): void

Kills an ongoing capture, e.g. when a timelapse length was set to undefined.

timelapse(options: Pick<CaptureOptions,'frames' | 'interval' | 'filename'>, callbacks?: Callbacks)

Captures multiple images in specified intervals for a specified or unspecified time.

3.4. Types and options

Capture Options

| Name | Type | Default | Description | | :----------------: | :------: | :-----------: | :--------------------------------------------------------------------------------: | | keep | boolean | false | Keep images on camera after capturing | | keepRAW | boolean | false | Keep RAW images on camera after capturing | | noKeep | boolean | true | Remove images from camera after capturing | | bulb | number | - | Set bulb exposure time in seconds | | frames | number | infinite | Set number of frames to capture (for a finite number has to have interval set) | | interval | number | 1 | Set capture interval in seconds | | resetInterval | boolean | false | Reset capture interval on signal (default=no) | | filename | string | capture%4n.%C | Specify a filename or filename pattern (see 2.1.3) | | forceOverwrite | boolean | true | Overwrite files without asking | | skipExisting | boolean | false | Skip existing files |

Command Result

CommandResult {
     error?: any;
     data?: any;
   }

Camera Params

| Name | Type | Default | Example value | | :-------: | :------: | :---------: | :---------------: | | model | string | - | Canon EOS 7D | | port | string | - | usb:020,006 | | configuration | object | - | try for yourself |

Callbacks

Callbacks {
  onData?: (data: any) => void;
  onError?: (error: any) => void;
  onClose?: (exitCode: number) => void;
}

Identificator

enum Identificator {
  Port,
  Model
}