Simple plugin to encode images to base64, client-side, with a mimetype conservation (jpg, png, gif, etc).
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.editorconfig
.gitignore
LICENSE
README.md
encode-image-uri.js
package.json

README.md

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 :)