crop-image-stream
v1.0.0
Published
Crop an image stream
Downloads
2
Readme
crop-image-stream
Crop an image stream
Crops a raw image stream, returns a cropped raw image stream, compatible with pixel-stream
. Everything is streams, so you can crop giant images without a memory overhead, only one line of the input image is held in memory at a time.
Table of Contents
Install
npm i --save crop-image-stream
Usage
See examples.
var fs = require('fs')
var path = require('path')
var JPEGDecoder = require('jpg-stream/decoder')
var JPEGEncoder = require('jpg-stream/encoder')
var Crop = require('crop-image-stream')
var inputFilename = path.join(__dirname, 'dramatic_chipmunk.jpg')
var outputFilename = path.join(__dirname, 'dramatic_chipmunk_crop.jpg')
var cropOpts = {
x: 575,
y: 20,
width: 275,
height: 200
}
fs.createReadStream(inputFilename)
.pipe(new JPEGDecoder())
.pipe(Crop(cropOpts))
.pipe(new JPEGEncoder())
.pipe(fs.createWriteStream(outputFilename))
API
var Crop = require('crop-image-stream')
Crop(opts)
Where:
opts.x
- X coordinate of left side of crop area, measured from the left of the original image. Default0
opts.y
- Y coordinate of top of crop area, measured from the top of the original image. Default0
opts.width
- Width of crop area. Default input image width. Ifopts.x + opts.width > inputImageWidth
, the crop area width will beinputImageWidth - opts.x
opts.height
- Height of crop area. Default input image height. Ifopts.y + opts.height > inputImageHeight
, the crop area height will beinputImageHeight - opts.y
You must pipe a stream of raw image data that emits a format
event with format = {height: inputImageHeight, width: inputImageWidth, colorSpace: inputImageColorSpace
. Returns a stream of raw image data which will also emit a format
event. Compatible with pixel-stream
but does not support frames (animated images).
Contribute
PRs accepted.
Small note: If editing the Readme, please conform to the standard-readme specification.
License
MIT © Digital Democracy