Code Monkey home page Code Monkey logo

color-transform's Introduction

color-transform

Streaming image color space transforms

Installation

npm install color-transform

Example

var ColorTransform = require('color-transform');

// Convert a buffer (list of supported transforms below)
var rgb = ColorTransform.cmyk2rgb(new Buffer([ 0, 56, 128, 32 ]))
// => new Buffer([ 1, 13, 20 ])

// Streaming example. Converts a CMYK JPEG to an RGB PNG
fs.createReadStream('cmyk.jpg')
  .pipe(new JPEGDecoder)
  .pipe(new ColorTransform('rgb'))
  .pipe(new PNGEncoder)
  .pipe(fs.createWriteStream('out.png'));

Supported color spaces

color-transform supports transforms between the following color spaces. The only exception is CMYK, which is currently only supported in one direction - you can convert from CMYK to any of the other color spaces, but not to CMYK.

  • 'rgb' - standard RGB
  • 'rgba' - RGB with alpha
  • 'gray' - grayspace
  • 'graya' - grayspace with alpha
  • 'cmyk' - CMYK

API

You can call the conversion functions directly with a buffer to convert, as shown in the example. The functions are named by joining the two color spaces with a 2, such as rgb2gray, and cmyk2rgb.

You can also use the streaming API, which is a pixel-stream. The constructor accepts two parameters: source color space, and destination color space. If you pipe another pixel-stream into color-transform, the source color space is optional in the constructor since it will be learned from the source stream.

You don't need to worry about writing to the stream in whole pixel chunks. The ColorTransform stream will automatically buffer if there is a chunk boundary in the middle of a pixel.

// create a stream that converts from cmyk to rgb
var s = new ColorTransform('cmyk', 'rgb');

// pipe a stream that happens to be cmyk to an rgb color transform.
fs.createReadStream('cmyk.jpg')
  .pipe(new JPEGDecoder)
  .pipe(new ColorTransform('rgb'))
  // ...

License

MIT

color-transform's People

Contributors

devongovett avatar

Watchers

 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.