question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Provide pre-pipeline function to modify options based on input image metadata

See original GitHub issue

This could seriously increase the power of Stream-based image processing.

Here’s an example of how halving an image’s dimensions could work:

// PROPOSED API NOT YET AVAILABLE
var halver = sharp().before(function(metadata) {
  this.resize(metadata.width / 2, metadata.height / 2);
});
readableStream.pipe(halver).pipe(writableStream);
// PROPOSED API NOT YET AVAILABLE

The existing metadata logic can also be improved to require only the first few hundred bytes of a Stream.

In addition, adding a “playbook” of example uses for this feature to the docs would be great too. There’s a variable/percentage extract/crop under discussion at #205 that this should allow for.

Issue Analytics

  • State:open
  • Created 8 years ago
  • Reactions:36
  • Comments:15 (3 by maintainers)

github_iconTop GitHub Comments

11reactions
gwen1230commented, Apr 30, 2018

Any news for this feature ?

6reactions
teoxoycommented, Dec 14, 2019

It will be nice to have this feature but I’m using image-size-stream as an alternative for now.

Example:

const fileStream = fs.createReadStream(path)
const sizeStream = new ImageDimensionsStream()
const bufferStream = new PassThrough().pause()

let stream = fileStream.pipe(sizeStream).pipe(bufferStream)

sizeStream.on('dimensions', ({ width, height }) => {
    // take decision based on image size
    if (W !== 0 && H !== 0 && (X !== 0 || Y !== 0 || width !== W || height !== H)) {
        const extractStream = sharp()
            .extract({ left: X, top: Y, width: W, height: H })
        stream = stream.pipe(extractStream)
    }
    bufferStream.resume()
    res.send(stream)
})

Using a paused PassThrough stream as buffer while ImageDimensionsStream returns the image dimensions works out nicely.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Modifying Image Metadata Without Recompressing Image
QA1895: Image I/O provides an API that allows for modifying image metadata without having to resave or recompress the image.
Read more >
Read and Edit Image Metadata with Python | by Kenneth Leung
We instantiate an exif Image Class by reading the image in a binary format before checking whether it contains any metadata. If so,...
Read more >
Metadata basics and actions in Lightroom Classic
Learn about Adobe Photoshop Lightroom Classic metadata (information about a photo, such as author name, resolution, color space, copyright, ...
Read more >
Input metadata - High performance Node.js image processing
A Promise is returned when callback is not provided. format : Name of decoder used to decompress image data e.g. jpeg , png...
Read more >
exiftool Application Documentation
So ExifTool alone may not be used to securely edit metadata in PDF files. ... the Image::ExifTool Options documentation), and provides a method...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found