Giter VIP home page Giter VIP logo

node-image-headers's Introduction

ImageHeaders

This is a simple class that can be used with a stream to read all the metadata from an image file without storing the entire file in memory.

Typically, most libraries in Node take in the stream, save it somewhere (either a Buffer or to disk), then hand the image file off to an external library.

We have a image uploader service that basically proxies through the stream directly to S3 - we don't want to hit our disk at all. This was the only way we could hit that goal and still get our metadata.

Usage

npm install node-image-headers

See the test file for how we are using it. Here's the key snippet:

image_headers = new ImageHeaders()

  new DataReader(file_name)
    .on "error", (error) ->
      console.log ("error: " + error)
      return callback(error)
    .on "byte", (b) ->
      # console.log ("byte: " + b)
      image_headers.add_bytes(b) unless image_headers.finished
    .on "end", () ->
      # console.log ("EOF");
      image_headers.finish (err, image_headers) ->
        return callback(err, image_headers)
    .read()

That's in CoffeeScript.

The finish call is important - it's what processes the EXIF tags (and in the future anything similar that can benefit from an external library). This keeps our code simpler from having us stream and parse EXIF on the fly. No library does this well, as far as I can find.

TODO

  • performance and general cleanup. This was a weekend hack (really a 24 hour one) and it shows.
  • clean up internals and exposed data structures. Right now, it's all properties on the object.
  • add support for additional metadata, including GPS and Camera model, as top level features

License

See the LICENSE file for details, but short version: MIT License.

node-image-headers's People

Contributors

sujal avatar

Watchers

Christian Landgren avatar James Cloos avatar  avatar

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.