# image-to-base64

> Generate a image to base64.

Latest version **2.2.0** (published 2021-04-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install image-to-base64
pnpm add image-to-base64
yarn add image-to-base64
bun add image-to-base64
```

## Health

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

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.2.0 |
| Published | 2021-04-09 |
| First published | 2017-10-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/image-to-base64) |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 27.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 132 |
| Author | Renan Bastos - |
| Maintainers | robsongajunior, renanbastos93 |
| Keywords | node, nodejs, module convert base64 nodejs, image2base64, image-to-base64, convert-image-base64, convert, save, code, base64, image, webpack, loader, img, src, img src |

## Links

- npm: https://www.npmjs.com/package/image-to-base64
- Repository: https://github.com/renanbastos93/image-to-base64
- Homepage: https://github.com/renanbastos93/image-to-base64#readme
- Issues: https://github.com/renanbastos93/image-to-base64/issues
- npm.io page: https://npm.io/package/image-to-base64

## Dependencies (1)

- [node-fetch](https://npm.io/package/node-fetch.md) ^2.6.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

- 2.2.0 (latest) — 2021-04-09
- 2.1.1 — 2020-07-22
- 2.1.0 — 2020-05-02
- 2.0.1 — 2018-09-21
- 2.0.0 — 2018-09-21
- 1.3.5 — 2018-03-26
- 1.3.1 — 2018-03-21
- 1.3.0 — 2018-02-15
- 1.2.0 — 2018-02-09
- 1.1.0 — 2017-11-01
- 1.0.1 — 2017-10-28
- 1.0.0 — 2017-10-27

## README

# image-to-base64
Generate a base64 code from an image through a URL or a path.
 
[![NPM Version][npm-image]][npm-url]
[![NPM Downloads][downloads-image]][downloads-url]
[![Build Status](https://travis-ci.org/renanbastos93/image-to-base64.svg?branch=master)](https://travis-ci.org/renanbastos93/image-to-base64)
![Tests](https://github.com/renanbastos93/image-to-base64/workflows/Tests/badge.svg)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/319a6e0b35474cf3ada5b0894e959b65)](https://www.codacy.com/app/renanbastos93/image-to-base64?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=renanbastos93/image-to-base64&amp;utm_campaign=Badge_Grade)
<a href="https://www.npmjs.com/package/vue"><img src="https://img.shields.io/npm/l/vue.svg" alt="License"></a>

[npm-image]: https://img.shields.io/npm/v/image-to-base64.svg
[npm-url]: https://npmjs.org/package/image-to-base64
[downloads-image]: https://img.shields.io/npm/dm/image-to-base64.svg
[downloads-url]: https://npmjs.org/package/image-to-base64

## About
It's a thing you can use in many situations, for example you can just save the base64 string in your database and increment it in the front-end with the `<img>` tag in HTML.

## Getting Started
Installation:
```bash
npm i -S image-to-base64
```
Code Example:
```js
const imageToBase64 = require('image-to-base64');
//or
//import imageToBase64 from 'image-to-base64/browser';

imageToBase64("path/to/file.jpg") // Path to the image
    .then(
        (response) => {
            console.log(response); // "cGF0aC90by9maWxlLmpwZw=="
        }
    )
    .catch(
        (error) => {
            console.log(error); // Logs an error if there was one
        }
    )
```
Remember that you can also use an image URL as a parameter.

Code Example:
```js
imageToBase64("https://whatever-image/") // Image URL
    .then(
        (response) => {
            console.log(response); // "iVBORw0KGgoAAAANSwCAIA..."
        }
    )
    .catch(
        (error) => {
            console.log(error); // Logs an error if there was one
        }
    )
```

#### Browser Usage
You can import image-to-base64 using the `<script>` tag in HTML.

Code Example:
```html
<script src="node_modules/image-to-base64/image-to-base64.min.js"></script>
```
Now you can use the module normally as in the JS examples above, but you can only use a URL and not a path. 

### LICENSE
[MIT](https://opensource.org/licenses/MIT) © 2017 RENAN.BASTOS

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