npm

npm’s 2019 JavaScript ecosystem survey analysis is now available! Get your copy here »

rawly

0.3.0 • Public • Published

Rawly NPM version Dependency Status

Extract previews from raw-files (with much help from Exiftools and Sharp)

The problem

You have a large set of RAW-images taken by your super camera. And you want to build a great looking showroom on the great internet 😏. But how do you preview those CR2's or NEF's to the people? The browser won't be able to show them. And it's very – and I do mean very – time consuming to go through every picture in Photoshop and extract those previews.

The solution

Rawly! With some great help from a NodeJS and workhorses Exiftools and Sharp. Rawly can iterate over your images and ”magically” extract those previews for you in quite a simple manner.

Installation

$ brew install exiftools
$ npm install --save rawly

Usage

Use Rawly to iterate over images in a folder and extract the images in that very same folder.

import glob from 'glob';
import Rawly from 'rawly';
// or if you're old-school: const Rawly = require('rawly').default <-- important to end with default
 
glob('./images/**/*.(CR2|NEF|...)', (paths) => {
  const rawlys = paths.map((path) => new Rawly(path));
  rawlys.forEach(rawly => {
    rawly.extractPreviews('1200x900', '-preview') // Scale to more reasonable size and append -preview to the end
      .then((extracted) => {
        if (extracted) console.log('Extracted a photo...');
        if (!extracted) console.log('Skipped this one because a preview was already extracted.');
      })
      .catch((err) => console.log(err.message));
  })
});

Methods

Rawly(path)

Create a a new instance of Rawly.

const rawly = new Rawly('path/to/a/raw-image');

rawly.extractPreviews([size], [suffix])

Extract previews of the image. Returns a Promise resolved to either true if an extraction took place, or false if a preview was already found in the same folder and it skipped extraction.

If you like you can specify dimensions to scale the preview image to. It will keep aspect ratio and won't crop, so the dimensions might not be exactly as specified.

The second argument is suffix, it's optional. But if it's provided it will append a string to the end of the file name of the extracted preview.

rawly.extractPreviews('1200x900', '-preview')
  .then((extracted) => {
    if (extracted) console.log(`Extracted previews for ${this.name}.`);
    if (!extracted) console.log(`Skipped extraction for ${this.name}.`);
  })
  .catch((err) => {
    console.error('An error occured:');
    console.error(err);
  });

Properties

Each instance of Rawly gets some properties attached to it which might be useful in your program:

const rawly = new Rawly('./images/unicorn.CR2');
console.log(rawly);
// Will output: {
//   path: './images/unicorn.CR2',
//   info: {
//     root: ''
//     dir: 'images',
//     base: 'unicorn.CR2',
//     ext: '.CR2',
//     name: 'unicorn',
//   },
//   previewExtracted: false,
// };

CLI

There is also a cli tool at your disposal if you wish.

$ brew install exiftools
$ npm install --global rawly

Usage

cd root/of/image-bank
$ rawly './**/*.(CR2|NEF|...)'

This will extract all possible previews from every file matching your glob pattern. To specify dimensions, use the -s (or --size) flag:

$ rawly './**/*.(CR2|NEF|...)' -s 1200x900

To append a suffix to your previews use the -e (or --ending) flag:

$ rawly './**/*.(CR2|NEF|...)' -e 'preview'

You can also print out this help if you might forget how it works:

$ rawly -h # or --help 
 
  Usage: rawly [options] <glob ...>
 
  Options:
 
    -h, --help             output usage information
    -V, --version          output the version number
    -s, --size [size]      Size of extracted preview (eg. "1200x900")
    -e, --ending [suffix]  String to append to end of file name
 

Tests

Tests are run with Tape. Clone this repo to run them:

$ git clone git@github.com:adambrgmn/rawly.git
cd rawly
$ npm install
$ npm test

Contribution

Contribution is very welcome. Just open an issue or make a pull-request and we will make things work together.

This package is still in a very early stage and it's not optimal. So if you want some features added, please reach out to me!

License

MIT © Adam Bergman

install

npm i rawly

Downloadsweekly downloads

17

version

0.3.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability