Giter Site home page Giter Site logo

extractd's Introduction

extractd

NPM version Downloads CircleCI

Extract previews from DSLR and mirrorless cameras' RAW files.

Installation

npm i extractd

Examples

Multiple examples can be located in examples directory

Usage

Workflow allows to extract previews directly from RAW files. Available options:

  • compact optional (boolean) - returns compact list of the preview files (defaults to false).
  • destination optional (string) - directory where preview image will be saved to; if destination does not exists it will be created (defaults to OS temp directory).
  • stream optional (boolean) - by default exif process generates the preview file in the temp directory in the OS or in destination if provided; once enabled preview is returned as a readeble stream which source will by automatically deleted after fully piped (defaults to false).
  • base64 optional (boolean) - returns base64 encoded preview string (defaults to false)
  • datauri optional (boolean) - returns datauri base64 encoded preview string (defaults to false).
  • persist optional (boolean) - by default exif process will be initialised and killed of per extractd call; with persist enabled same exif process can be used across all calls for single file and batch processing (defaults to false).

Orientation of extracted images will be corrected based on metadata available in the source file.

Basic usage

const extractd = require('extractd');

(async () => {

    const done = await extractd.generate('/directory/nikon_d850_01.nef');

})();

Response done (object) will be similar to:

  {
    preview: '/tempdirectory/nikon_d850_01.jpg',
    source: '/directory/nikon_d850_01.nef'
  }
  • preview - location of the preview image
  • source - location of the original RAW image

Base64 usage

const extractd = require('extractd');

(async () => {

    const done = await extractd.generate('/directory/nikon_d850_01.nef', {
        base64: true,
        datauri: true
    });

})();

Response done (object) will be similar to:

  {
    preview: 'data:image/jpeg;base64,/9j/2wCEAAQGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHR...',
    source: '/directory/nikon_d850_01.nef'
  }
  • preview - datauri base64 preview image
  • source - location of the original RAW image

Persistent status check

const done = await extractd.generate('/directory/nikon_d850_01.nef', {
  persist: true,
  destination: '/directory/'
});

const status = extractd.status();

const desist = await extractd.desist();

Response done (object) will be similar to:

  {
    preview: '/directory/nikon_d850_01.jpg',
    source: '/directory/nikon_d850_01.nef'
  }

Response status (object) will be similar to:

{
  persistent: true
}
  • persistent - status indicates that exif process is already live and additional calls can join in or next call should terminate it

Response desist (object) will be similar to:

{
  persistent: false
}
  • persistent - exif process has been killed off with desist and additional calls with persist would start new exif process

Basic stream usage

const extractd = require('extractd');
const pipeline = require('util').promisify(require('stream').pipeline);

(async () => {

    const done = await extractd.generate('/directory/nikon_d850_01.nef', {
        stream: true
    });

    await pipeline(done.preview, require('fs').createWriteStream('/my/new/directory/nikon_d850_01.jpg'));

})();

Response done (object) will be similar to:

  {
    preview: ReadStream,
    source: '/directory/nikon_d850_01.nef'
  }
  • preview - readable stream which source will be deleted once fully piped
  • source - location of the original RAW image

Base64 stream usage

const extractd = require('extractd');
const pipeline = require('util').promisify(require('stream').pipeline);

(async () => {

    const done = await extractd.generate('/directory/nikon_d850_01.nef', {
        stream: true,
        base64: true,
        datauri: true
    });

    await pipeline(done.preview, require('fs').createWriteStream('/my/new/directory/nikon_d850_01.txt'));

})();

Response done (object) will be similar to:

  {
    preview: ReadStream,
    source: '/directory/nikon_d850_01.nef'
  }
  • preview - readable datauri base64 stream
  • source - location of the original RAW image

Complex usage

const canon = await extractd.generate('/directory/canon_eos_5d_mark_iv_01.cr2', {
  compact: true,
  persist: true
});

const nikon = await extractd.generate('/directory/nikon_d850_01.nef', {
  compact: true,
  persist: true
});

const panasonic = await extractd.generate('/directory/panasonic_s1r_01.rw2', {
  compact: true
});

const done = [canon, nikon, panasonic];

Response done (array) will be similar to:

[
  '/tempdirectory/canon_eos_5d_mark_iv_01.jpg',
  '/tempdirectory/nikon_d850_01.jpg',
  '/tempdirectory/panasonic_s1r_01.jpg'
]

As persist option was used only single exif process was used across all three calls. Last item terminates exif process as persist defaults to false.

Batch usage

const extractd = require('extractd');

(async () => {

    const done = await extractd.generate([
      '/directory/nikon_d850_01.nef',
      '/directory/sony_a7r_iii_01.arw',
      '/directory/pentax_k_1_mark_ii_01.dng'
    ]);

})();

Response done (array) will be similar to:

  [
    {
      preview: '/tempdirectory/nikon_d850_01.jpg',
      source: '/directory/nikon_d850_01.nef'
    },
    {
      preview: '/tempdirectory/sony_a7r_iii_01.jpg',
      source: '/directory/sony_a7r_iii_01.arw'
    },
    {
      preview: '/tempdirectory/pentax_k_1_mark_ii_01.jpg',
      source: '/directory/pentax_k_1_mark_ii_01.dng'
    }
  ]

Advanced usage

const extractd = require('extractd');

(async () => {

    const batch = await extractd.generate([
      '/directory/nikon_d850_01.nef',
      '/directory/sony_a7r_iii_01.arw',
      '/directory/pentax_k_1_mark_ii_01.dng'
    ], {
      persist: true
    });

    const file01 = await extractd.generate('/directory/fujifilm_gfx_50s_01.raf', {
      persist: true
    });

    const file02 = await extractd.generate('/directory/panasonic_s1r_01.rw2');

    const done = [...batch, ...[file01], ...[file02]];

})();

Response done (array) will be similar to:

  [
    {
      preview: '/tempdirectory/nikon_d850_01.jpg',
      source: '/directory/nikon_d850_01.nef'
    },
    {
      preview: '/tempdirectory/sony_a7r_iii_01.jpg',
      source: '/directory/sony_a7r_iii_01.arw'
    },
    {
      preview: '/tempdirectory/pentax_k_1_mark_ii_01.jpg',
      source: '/directory/pentax_k_1_mark_ii_01.dng'
    },
    {
      preview: '/tempdirectory/fujifilm_gfx_50s_01.jpg',
      source: '/directory/fujifilm_gfx_50s_01.raf'
    },
    {
      preview: '/tempdirectory/panasonic_s1r_01.jpg',
      source: '/directory/panasonic_s1r_01.rw2'
    }
  ]

As persist option was used only single exif process was used across all three calls. Last item terminates exif process as persist defaults to false.

Errors

All erros are resolved and fallow similar convention:

const extractd = require('extractd');

(async () => {

    const done = await extractd.generate('/directory/dummyFile.nef');

})();

Response done (object) will be similar to:

{
  error: 'File not found',
  source: '/directory/dummyFile.nef'
}

Tests

To run all available tests

npm test

Test samples

All test samples are based on original raw files sourced from photography blog, hasselblad, and imaging-resource sites.

License

The MIT License (MIT). Please see license file for more information.

extractd's People

Contributors

przemyslawpluta avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

woss

extractd's Issues

Accept buffer input

Hi! first of all thanks for this awesome library!

would it be possible to accept buffer as input?
My use case is get s3 object and store in buffer and use that buffer as an input to generate the jpeg version.

Extractd does not work with directories that contains accents

When I try to use extractd with a file path that have accents (ó, for example), it does not find the file.

const done = await extractd.generate('D:\\Fótos\\Image.CR2', {
    destination: '/temp/dir/'
 });

// Throws excepiton: 'File not found'

What can I do about it?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.