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.

Get image width and height from stream

See original GitHub issue

Hi! Thanks for an excellent module!

I’m trying to read image width and height from a stream, but nothing happens. In the code below nothing is printed to console. If I remove .pipe(metaReader) the response is printed etc.

What am I missing?

    const request = require('request')
    const sharp = require('sharp')

    let image

    const metaReader = sharp()
      .on('info', info => {
        image = info
      })
      .on('error', err => {
        console.log(err)
      })

    request
      .get('https://images-na.ssl-images-amazon.com/images/M/MV5BMTUyMjM2NTgwNl5BMl5BanBnXkFtZTgwMTUzOTUwMjI@._V1_SX1777_CR0,0,1777,999_AL_.jpg')
      .pipe(metaReader)
      .on('response', function(response) {
        console.log(response) // 200
      })
      .on('error', err => {
        console.log(err)
      })
      .on('end', () => {
        console.log('end')
      })

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
lovellcommented, Apr 21, 2017

You’ll need to tell metaReader what to do. If you’re expecting metadata about the input image then try something like (untested):

const metaReader = sharp()
  .metadata()
  .then(info => {
    console.log(info)
  })
  .catch(err => {
    console.log(err)
  })
1reaction
lovellcommented, May 13, 2017

Sorry, missed your question (too many GH notifications)… you should be able to get away with passing a truncated Buffer with only the header to read image dimensions, but watch out for things like large ICC profiles that can be part of the header. Hope this helps.

Read more comments on GitHub >

github_iconTop Results From Across the Web

how can I get image size (w x h) using Stream - Stack Overflow
First you have to write the image: System.Drawing.Image image = System.Drawing.Image.FromStream (new System.IO.MemoryStream(byteArrayHere));.
Read more >
Width and height of image from byte array C# - MSDN - Microsoft
Best way to get width and height is convert bytes first to image and read from that. For example following code creates Stream...
Read more >
C# aspose : how to get width/height of an image/stream to do ...
Here is the code how to get image width/height with .NET System.Drawing : Image image = Image.FromStream(stream); Console.WriteLine($"{image ...
Read more >
How to find width and height of an image using Python?
In order to find the height and width of an image, there are two approaches. The first approach is by using the PIL(Pillow)...
Read more >
getimagesize - Manual - PHP
The getimagesize() function will determine the size of any supported given image file and return the dimensions along with the file type and...
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