# image-data-uri

> Library to easily decode/encode Data URI images

Latest version **2.0.1** (published 2019-07-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install image-data-uri
pnpm add image-data-uri
yarn add image-data-uri
bun add image-data-uri
```

Provides the command `image-data-uri`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2019-07-30 |
| First published | 2016-04-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 46.6 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 66 |
| Author | Diego ZoracKy |
| Maintainers | diegozoracky |
| Keywords | image, data uri, image data uri, base 64, image base 64, data uri base 64 |

## Links

- npm: https://www.npmjs.com/package/image-data-uri
- Repository: https://github.com/DiegoZoracKy/image-data-uri
- Homepage: https://github.com/DiegoZoracKy/image-data-uri#readme
- Issues: https://github.com/DiegoZoracKy/image-data-uri/issues
- npm.io page: https://npm.io/package/image-data-uri

## Dependencies (4)

- [magicli](https://npm.io/package/magicli.md) 0.0.8
- [request](https://npm.io/package/request.md) ^2.88.0
- [fs-extra](https://npm.io/package/fs-extra.md) ^0.26.7
- [mime-types](https://npm.io/package/mime-types.md) ^2.1.18

## Alternatives

- [exif-parser](https://npm.io/package/exif-parser.md) — 3.8M weekly downloads
- [vite-plugin-compression](https://npm.io/package/vite-plugin-compression.md) — 569.5K weekly downloads
- [pica](https://npm.io/package/pica.md) — 442.4K weekly downloads
- [@reportportal/client-javascript](https://npm.io/package/@reportportal/client-javascript.md) — 408.8K weekly downloads
- [@tldraw/state](https://npm.io/package/@tldraw/state.md) — 316.0K weekly downloads

## Recent versions

- 2.0.1 (latest) — 2019-07-30
- 2.0.0 — 2018-09-21
- 1.1.1 — 2018-05-19
- 1.1.0 — 2018-05-03
- 1.0.1 — 2017-11-09
- 1.0.0 — 2016-04-02

## README

# Image Data URI

Library to easily decode/encode Data URI images

## Installation

```bash
npm install image-data-uri
```
**CLI**
```bash
npm install image-data-uri -g
```
```bash
npx image-data-uri --help
```

## Methods

- **decode(dataURI)**
```javascript
imageDataURI.decode('data:image/png;base64,SOMEPNGDATAURI/wD/')

// RETURNS
{
    imageType: 'image/png',
    dataBase64: 'SOMEPNGDATAURI/wD/',
    dataBuffer: <Buffer 89 50 4e 47 0d 0a ...>
}
```

- **encode(data, mediaType)**
```javascript
// Expects a Buffer of a image file
let dataBuffer = new Buffer(imageData);

// PNG | GIF | etc.
let mediaType = 'PNG';

// RETURNS :: image data URI :: 'data:image/png;base64,PNGDATAURI/wD/'
imageDataURI.encode(dataBuffer, mediaType)
```

- **encodeFromURL(imageURL)**
```javascript
// Returns a Promise
imageDataURI.encodeFromURL('http://www.some-site.com/some-image.png')

    // RETURNS image data URI :: 'data:image/png;base64,PNGDATAURI/'
    .then(res => console.log(res))
```
- **encodeFromFile(filePath)**
```javascript
// Returns a Promise
imageDataURI.encodeFromFile('./some-file.png')

    // RETURNS image data URI :: 'data:image/png;base64,PNGDATAURI/'
    .then(res => console.log(res))
```
- **outputFile(dataURI, filePath)**
```javascript
// Some image data uri
let dataURI = 'data:image/png;base64,PNGDATAURI/';

// It will create the full path in case it doesn't exist
// If the extension is defined (e.g. fileName.png), it will be preserved, otherwise the lib will try to guess from the Data URI
let filePath = './out/path/fileName';

// Returns a Promise
imageDataURI.outputFile(dataURI, filePath)

    // RETURNS image path of the created file 'out/path/fileName.png'
    .then(res => console.log(res))
```

---
_Source: https://npm.io/package/image-data-uri · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
