Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/emmanuelbeziat/encode-image-uri

🖼 Simple plugin to encode images to base64, client-side, with a mimetype conservation (jpg, png, gif, etc).
https://github.com/emmanuelbeziat/encode-image-uri

base64 client-side encoding javascript uri

Last synced: about 2 months ago
JSON representation

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

Awesome Lists containing this project

README

        

# encode-image-uri

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

## Installation

```bash
# npm
$ npm i encode-image-uri

# yarn
$ yarn add encode-image-uri
```

## How to use

```javascript
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

```html

```

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