Image encoding in Node JS
11 Apr 2019This article is work in progress!
While programming on a side project, I had to deal with images in a node application. My application is using Express, Amazon Rekognition as well as Pouchdb.
I was dealing with different sources & targets:
- A user uploads a picture
- I read a picture from file, be it in JPEG or PNG format
- I send a picture to AWS
- I store a picture in my pouchDB
While browsing the different sources, I encountered various formats on how images can be handled in node:
- As buffer containing binary data
- As string conatining Base64 encoded data, starting with something like
data:image/jpeg;base64,
(or withpng
) - As string containing base64 encoded data without the special beginning
These are the different operations I am doing and what they provide as output:
-
Reading a file from disk with
fs
: return aBuffer
with binary data
These are the sources and targets in/from which image data is transferred in my example:
Reading
Helpful stuff I found about the topics: