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-raspistill

v2.0.1

Published

Node wrapper for taking photos using Raspberry Pi raspistill app.

Downloads

105

Readme

node-raspistill

Build status Coverage Status Total alerts Language grade: JavaScript

Simple wrapper for taking photos using Raspberry Pi raspistill app.

Module is written in typescript and provides type definitions out-of-the-box.

Tested with Raspberry Pi 2 B (Raspbian OS), and Raspberry Camera Module v2.

Requirements

Raspbian OS with node.js 12+ installed, raspberry camera module connected to your pi.

Usage

You can check a lot of examples here.

Sample usage:

npm install node-raspistill
const Raspistill = require('node-raspistill').Raspistill;
const camera = new Raspistill();

camera.takePhoto().then((photo) => {
    ...
});

Or (if you use imports):

import {Raspistill} from 'node-raspistill';
const camera = new Raspistill();

camera.takePhoto().then((photo) => {
    ...
});

You can also pass some options to constructor method:

const camera = new Raspistill({
    verticalFlip: true,
    width: 800,
    height: 600
});

See full options list in the docs below.

Changelog

You can see changelog here.

Docs

Raspistill

constructor(options?: ICameraOptions)

Creates new Raspistill instance.

|key|type|defaults|desc| |---|---|---|---| |noFileSave|boolean|false|Disables photos saving. If true - camera output will be directly sent as Buffer without saving on the drive| |verticalFlip|boolean|false| | |horizontalFlip|boolean|false| | |noPreview|boolean|true|Disables preview window on Pi while taking photo| |outputDir|string|'./photos'|Output directory where photos will be stored| |fileName|string|undefined|Name for photo file. If undefined - photos file names will be calculated as new Date.now() + file encoding| |encoding|string|'jpg'|'jpg', 'bmp', 'gif' or 'png'| |width|number|undefined|Width of taken image in pixels. If width is not set - raspistill uses default max camera sensor resolution width| |height|number|undefined|Height of taken image in pixels. If height is not set - raspistill uses default max camera sensor resolution height| |time|number|undefined|Time before camera takes photo. If undefined raspistill util use it's own 5 sec timeout| |shutterspeed|number|undefined|Shutter speed in microseconds| |contrast|number|undefined|Contrast of the image (-100 ... 100). If undefined - raspistill util use contrast 0 value | |brightness|number|undefined|Brightness of the image. 50 is the default raspistill util value.| |saturation|number|undefined|Image saturation (-100 ... 100). Raspistill util uses 0 value if undefined| |iso|number|undefined|Capture ISO (100 ... 800)| |rotation|number|undefined|Image rotation param| |awb|string|undefined|'off', 'auto', 'sun', 'cloud', 'shade', 'tungsten', 'fluorescent', 'incandescent', 'flash', 'horizon'| |awbg|string|undefined|Sets blue and red gains (as floating point numbers) to be applied when awb=off. e.g. '1.5,1.2'| |quality|number|undefined|JPEG quality <0 to 100>| |thumb|string|undefined|Specification of the thumbnail image inserted into the JPEG file. If not specified, defaults are a size of 64x48 at quality 35| |exposure|string|'auto'|'auto', 'night', 'nightpreview', 'backlight', 'spotlight', 'sports', 'snow', 'beach', 'verylong', 'fixedfps', 'antishake', 'fireworks'| |flicker|string|'off'|'off', 'auto', '50hz','60hz'| |imageEffect|string|'none'|'none','negative', 'solarise', 'posterise', 'whiteboard', 'blackboard', 'sketch', 'denoise', 'emboss', 'oilpaint', 'hatch', 'gpen', 'pastel', 'watercolour', 'film', 'blur', 'saturation'| |drc|string|'off'|'off', 'low', 'med', 'high'|

const camera = new Raspistill({
    verticalFlip: true,
    fileName: 'foo'
});

You can find more info about raspistill util options in the official docs: https://www.raspberrypi.org/documentation/raspbian/applications/camera.md


takePhoto(fileName?: string): Promise<Buffer>

Takes new photo. Returns Promise, resolving with Buffer object.

camera.takePhoto('testPhotoName').then((photo) => {
    ...
});

timelapse(fileName: string, intervalMs: number, execTimeMs: number, cb: (image: Buffer) => any): Promise<void>;

timelapse(intervalMs: number, execTimeMs: number, cb: (image: Buffer) => any): Promise<void>;

Runs camera in timelapse mode. Passes taken image picture as Buffer object to the callback. Raspistill options (passed into constructor or into setOptions method) are also applicable in this mode.

Remember that raspberry camera has it's own limits of taking photos speed even in timelapse mode.

Check out official raspistill docs (https://www.raspberrypi.org/documentation/raspbian/applications/camera.md) for file naming rules and interval/total exec time params usage.

camera.timelapse(500, 3000, (image) => {
    // got image from camera, do something
}).then(() => {
    // timelapse ended
}).catch((err) => {
    // something bad happened
});

or

camera.timelapse('image%04d', 500, 3000, (image) => {
    // got image from camera, do something
}).then(() => {
    // timelapse ended
}).catch((err) => {
    // something bad happened
});

stop(): void;

Tries to stop current raspistill running action. Note that pending raspistill promises will be rejected with RaspistillInterruptError if stop was completed.

const RaspistillInterruptError = require('node-raspistill').RaspistillInterruptError;

raspistill.timelapse(1000, 30000, (image) => {
    console.log('got photo, trying to stop raspistill');
    raspistill.stop();
})
    .then(() => {
        console.log('timelapse ended')
    })
    .catch((err) => {
        console.log(err instanceof RaspistillInterruptError) // true, raspistill was interrupted;
    });

setOptions(options: ICameraOptions): void

Sets new options for current Raspistill instance.

camera.setOptions({
    horizontalFlip: true,
    noPreview: false
});

getOptions(): ICameraOptions

Gets current raspistill options.


getOption(key: string): any

Gets current raspistill option by key.


Contributors

Just want to say thx for all contributors. You are wonderful. :)