Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

crop-image-stream

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

crop-image-stream

Crop an image stream

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

crop-image-stream

npm js-standard-style

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. Default 0
  • opts.y - Y coordinate of top of crop area, measured from the top of the original image. Default 0
  • opts.width - Width of crop area. Default input image width. If opts.x + opts.width > inputImageWidth, the crop area width will be inputImageWidth - opts.x
  • opts.height - Height of crop area. Default input image height. If opts.y + opts.height > inputImageHeight, the crop area height will be inputImageHeight - 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

Keywords

FAQs

Package last updated on 21 Jan 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc