
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
A streaming JPEG encoder and decoder for Node and the browser. It is a direct compilation of libjpeg to JavaScript using Emscripten.
npm install jpg-stream
For the browser, you can build using Browserify.
This example uses the concat-frames module to collect the output of the JPEG decoder into a single buffer. It also shows how to get EXIF metadata contained in the JPEG file.
var JPEGDecoder = require('jpg-stream/decoder');
var concat = require('concat-frames');
// decode a JPEG file to RGB pixels
fs.createReadStream('in.jpg')
.pipe(new JPEGDecoder)
.on('meta', function(meta) {
// meta contains an exif object as decoded by
// https://github.com/devongovett/exif-reader
})
.pipe(concat(function(frames) {
// frames is an array of frame objects (one for JPEGs)
// each element has a `pixels` property containing
// the raw RGB pixel data for that frame, as
// well as the width, height, etc.
}));
Large JPEGs from DSLRs can be somewhat slow to decode. If you don't need the image at its full size for preview, or will be resizing the image anyway, there is an option to perform scaling at decode time. This improves performance dramatically since only the DCT coefficients necessary for the desired size are decoded.
To specify decode scaling, provide width and height options to the decoder. This
represents the minimum size you want, and the decoder will output an image of at least
this size, but likely not exactly that size. For exact resizing, provide your minimum
allowed size to the decoder and use the resize-pixels
module to resize the JPEG decoder's output to the exact size.
fs.createReadStream('large.jpg')
.pipe(new JPEGDecoder({ width: 600, height: 400 }))
.pipe(concat(function(frames) {
// frames[0].width >= 600 and frames[0].height >= 400
}));
You can encode a JPEG by writing or piping pixel data to a JPEGEncoder stream.
You can set the quality option to a number between 1 and 100 to control the
size vs quality tradeoff made by the encoder.
The JPEG encoder supports writing data in the RGB, grayscale, or CMYK color spaces. If you need to convert from another unsupported color space, first pipe your data through the color-transform module.
var JPEGEncoder = require('jpg-stream/encoder');
var ColorTransform = require('color-transform');
// convert a PNG to a JPEG
fs.createReadStream('in.png')
.pipe(new PNGDecoder)
.pipe(new JPEGEncoder({ quality: 80 }))
.pipe(fs.createWriteStream('out.jpg'));
// colorspace conversion to convert from RGBA to RGB
fs.createReadStream('rgba.png')
.pipe(new PNGDecoder)
.pipe(new ColorTransform('rgb'))
.pipe(new JPEGEncoder)
.pipe(fs.createWriteStream('rgb.jpg'));
MIT
FAQs
A streaming JPEG encoder and decoder
The npm package jpg-stream receives a total of 390 weekly downloads. As such, jpg-stream popularity was classified as not popular.
We found that jpg-stream demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.