encode-image-uri

2.0.0 • Public • Published

encode-image-uri

Simple plugin to encode images to base64, with a mimetype conservation (jpg, png, gif, etc).

Installation

# npm 
$ npm i encode-image-uri
 
# yarn 
$ yarn add encode-image-uri

How to use

const encodeImageURI = require('encode-image-uri')
 
encodeImageURI(image)
    .then(base64 => {
        console.log(base64)
        // Do your stuff
    })
    .catch(error => {
        console.error(error)
        // Handle your error
    })

Note that the image fiven must be a File object.

Example

Image from an input with multiple files

<input type="file" class="input-file" multiple>
documment.querySelector('.input-file').addEventListener(event, (event) => {
    const fileList = event.target.files
 
    Array.from(fileList).forEach(image => {
        encodeImageURI(image).then(base64 => {
            console.log(base64)
        })
    })
})

Contribute

I’ll happily get your PR :)

Package Sidebar

Install

npm i encode-image-uri

Weekly Downloads

19

Version

2.0.0

License

MIT

Unpacked Size

3.03 kB

Total Files

5

Last publish

Collaborators

  • emmanuelbeziat