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

inkjet

v3.0.0

Published

JPEG-image decoding, encoding & EXIF reading library for browser and node.js

Downloads

784

Readme

inkjet-logo

Node.js CI

JPEG-image decoding, encoding & EXIF reading library for a browser and node.js

browser-matrix

Installation

installing with npm:

npm install inkjet --save

In browser

To use inkjet in a browser, use inkjet.js or inkjet.min.js in /dist directory, or build it manually:

npm install
npm run browser

Usage

Decoding, encoding and EXIF extraction operations are offloaded to WebWorkers if the environment supports them.

Decode JPEG

var inkjet = require('inkjet');

var filepath = './images/js_logo-4-2-0.jpg';
var buf = fs.readFileSync(filepath);

inkjet.decode(buf, function(err, decoded) {
  // decoded: { width: number, height: number, data: Uint8Array }
});

Encode JPEG

var inkjet = require('inkjet');

var width = 320;
var height = 180;
var frameData = new Buffer(width * height * 4);
var i = 0;

while (i < frameData.length) {
  frameData[i++] = 0xFF; // R, red
  frameData[i++] = 0x00; // G, green
  frameData[i++] = 0x00; // B, blue
  frameData[i++] = 0xFF; // A, alpha - ignored in JPEGs
}

var buf = frameData;
var options = {
  width: width,
  height: height,
  quality: 80
};

inkjet.encode(buf, options, function(err, encoded) {
  // encoded: { width: number, height: number, data: Uint8Array }
});

Read EXIF

var inkjet = require('inkjet');

var filepath = './images/js_logo-exif.jpg';
var buf = fs.readFileSync(filepath);
inkjet.exif(buf, function(err, metadata) {
  // metadata -- an object that maps EXIF tags to string values
});

Deduce image type

var inkjet = require('inkjet');

var filepath = './images/js_logo-4-2-0.jpg';
var buf = fs.readFileSync(filepath);
inkjet.magic(buf, function(err, data) {
  // data -- an object that contains mime-type and extension
});

Image information

var inkjet = require('inkjet');

var filepath = './images/js_logo-4-2-0.jpg';
var buf = fs.readFileSync(filepath);
inkjet.info(buf, function(err, data) {
  // data -- an object that contains width, height, mime type and extension data
});

API

.decode(buf, [options], cb);

Decodes a JPEG image.

Arguments:

  • buf - source buffer, one of the following types: Buffer|ArrayBuffer|Uint8Array|Uint8ClampedArray
  • [options] - an optional object with settings to decode an image. Supported options:
    • width - override image width
    • height - override image height
  • cb - a callback that gets 2 arguments:
    • err - decoding Error
    • decoded - an object that describes the decoded image: { width: number, height: number, data: Uint8Array } where data represents colors in RGBA format.
inkjet.decode(buf, function(err, decoded) {
  // ...
});

.encode(buf, [options], cb);

Encodes the provided buffer to a JPEG format.

Arguments:

  • buf - source buffer, one of the following types: Buffer|ArrayBuffer|Uint8Array|Uint8ClampedArray
  • [options] - an optional object with settings to encode an image. Supported options:
    • width - width of the image in buf
    • height- height of the image in buf
    • quality - a numberic value [0-100], describes quality of encoding. 0 - low quality, 100 - high quality.
  • cb - a callback that gets 2 arguments:
    • err - encoding Error
    • encoded - an object that describes the encoded image: { width: number, height: number, data: Uint8Array }
inkjet.encode(buf, function(err, encoded) {
  // ...
});

.exif(buf, [options], cb);

Get EXIF metadata for the image. The metadata tags defined in the Exif standard cover date and time information, camera settings, descriptions, resolution and location information.

Arguments:

  • buf - source buffer, one of the following types: Buffer|ArrayBuffer|Uint8Array|Uint8ClampedArray
  • [options] - an optional object with settings to encode an image. Supported options:
    • hasMakerNote - exclude MakerNote tag from metadata. Default value: true, MakerNote tag is excluded.
  • cb - a callback that gets 2 arguments:
    • err - exif extraction Error
    • metadata - metadata object, a set of tags and their values.
inkjet.exif(buf, function(err, metadata) {
  // ...
});

.magic(buf, cb);

Deduce image type (mime type and extension) for the provided buffer.

Arguments:

  • buf - source buffer, one of the following types: Buffer|ArrayBuffer|Uint8Array|Uint8ClampedArray
  • cb - a callback that gets 2 arguments:
    • err - Error object
    • data - data object { "mimeType": string, "extension": string }
inkjet.magic(buf, function(err, data) {
  // ...
});

.info(buf, cb);

Get image information without reading and decoding an image.

Arguments:

  • buf - source buffer, one of the following types: Buffer|ArrayBuffer|Uint8Array|Uint8ClampedArray
  • cb - a callback that gets 2 arguments:
    • err - Error object
    • data - data object { "type": string, "mimeType": string, "extension": string, "width": number, "height: number" }
inkjet.info(buf, function(err, data) {
  // data: {
  //   type: "image"
  //   mimeType: ...
});

Tests

To run the tests for inkjet in Node.js:

npm test

To run tests in a browser:

npm run bundle:test

a bundle file inkjet-test-bundle.js with all tests will be generated in inkjet/test/browser directory.

Open inkjet/test/browser/index.html in the target browser. Tests will run automatically.

Contact

[Grigorii Chudnov] (mailto:[email protected])

License

Distributed under the The MIT License (MIT).