S
S
Stanislav2018-12-02 16:49:13
Node.js
Stanislav, 2018-12-02 16:49:13

How to get information about a photo from the buffer?

There is a buffer with a photo, you need to find out the mime type, width, height before saving.
Is it possible to do this?
I know that you can pull out the info using gm or sharp, but as I understand it, in order to get some data, you first need to save the whole thing on the server, but you want to transfer the buffer directly, unattend what you need, and only then think whether you need to save the photo or not.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladlen Hellsite, 2018-12-06
@ms-dred

Load buffer into sharp and get metadata :

sharp(youBuffer).metadata().then((metadata) => {
  console.log('Width', metadata.width, 'Height', metadata.height, 'Format', metadata.format);
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question