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

rawly

v0.3.0

Published

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

Downloads

24

Readme

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 :smirk:. 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 [email protected]: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