# base64-img

> Convert img or svg to base64, or convert base64 to img

Latest version **1.0.4** (published 2018-02-13) · ISC license · 0 weekly downloads

## Install

```sh
npm install base64-img
pnpm add base64-img
yarn add base64-img
bun add base64-img
```

## 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 | 1.0.4 |
| Published | 2018-02-13 |
| First published | 2015-03-02 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 11 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 164 |
| Author | douzi |
| Maintainers | douzi |
| Keywords | base64, img, image, img base64, svg |

## Links

- npm: https://www.npmjs.com/package/base64-img
- Repository: https://github.com/douzi8/base64-img
- Issues: https://github.com/douzi8/base64-img/issues
- npm.io page: https://npm.io/package/base64-img

## Dependencies (2)

- [file-system](https://npm.io/package/file-system.md) ^2.1.0
- [ajax-request](https://npm.io/package/ajax-request.md) ^1.2.0

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [jwt-simple](https://npm.io/package/jwt-simple.md) — 259.5K weekly downloads
- [@exodus/patch-broken-hermes-typed-arrays](https://npm.io/package/@exodus/patch-broken-hermes-typed-arrays.md) — 28.5K weekly downloads
- [@native-to-anchor/buffer-layout](https://npm.io/package/@native-to-anchor/buffer-layout.md) — 12.2K weekly downloads
- [binary-parser-encoder](https://npm.io/package/binary-parser-encoder.md) — 5.3K weekly downloads

## Recent versions

- 1.0.4 (latest) — 2018-02-13
- 1.0.3 — 2015-03-25
- 1.0.1 — 2015-03-02
- 1.0.0 — 2015-03-02

## README

# base64-img
Convert img to base64, or convert base64 to img
```js
var base64Img = require('base64-img');
```
## install
```
npm install base64-img --save
```
## test
```
mocha
```
## API
### .base64(filename, callback)
Convert image file to image base64 data
* {string} ``filename`` required  
The image path
* {function} ``callback(err, data)`` required  
Callback with image base64 data
```js
base64Img.base64('path/demo.png', function(err, data) {})
```

### .base64Sync(filename)
The api same as base64, but it's synchronous 
```js
var data = base64Img.base64Sync('path/demo.png');
var data2 = base64Img.base64Sync('path/demo.svg');
```

### .requestBase64(url, callback)
* {string} ``url`` required
* {function} ``callback(err, res, body)`` required  
Callback with http request
```js
var url = 'http://../demo.png';
base64Img.requestBase64(url, function(err, res, body) {
  
});
```

### .img(data, destpath, name, callback)
Convert image base64 data to image
* {string} ``data`` required  
Image base64 data
* {string} ``destpath`` required  
Dest path, if the destpath is root, pass empty string
* {string} ``name`` required  
The image's filename
* {function} ``callback(err, filepath)`` required
```js
base64Img.img('data:image/png;base64,...', 'dest', '1', function(err, filepath) {});
```

### .imgSync(data, destpath, name)
The api same as img, but it's synchronous
```js
var filepath = base64Img.imgSync('data:image/png;base64,...', '', '2');
```

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