# react-native-image-base64-png

> Convert PNG images to base64

Latest version **0.2.1** (published 2022-05-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-native-image-base64-png
pnpm add react-native-image-base64-png
yarn add react-native-image-base64-png
bun add react-native-image-base64-png
```

## Health

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

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

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.1 |
| Published | 2022-05-04 |
| First published | 2021-09-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 16.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Snapp |
| Maintainers | tommyrharper |
| Keywords | react-native, base64, png |

## Links

- npm: https://www.npmjs.com/package/react-native-image-base64-png
- Repository: https://github.com/tommyrharper/react-native-image-base64-png
- Homepage: https://github.com/tommyrharper/react-native-image-base64-png#readme
- Issues: https://github.com/tommyrharper/react-native-image-base64-png/issues
- npm.io page: https://npm.io/package/react-native-image-base64-png

## 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

- 0.2.1 (latest) — 2022-05-04
- 0.2.0 — 2021-09-14
- 0.1.9 — 2021-09-14
- 0.1.8 — 2021-09-14
- 0.1.7 — 2021-09-14
- 0.1.6 — 2021-09-14

## README

# react-native-image-base64-png

This is a fork of [this](https://github.com/Snapp-FidMe/react-native-image-base64) library, modified to support png on android and export typescript types.

That repo in turn is a working rewrite of [this](https://github.com/xfumihiro/react-native-image-to-base64) abandoned library.
It provides a very simple way to convert an image to a base64 string.

If you encounter `OOM` errors on old android devices, make sure you optimize the image's size before you convert it. 
Indeed working with big images on Android might cause very high memory usage.

## Getting started

`npm install react-native-image-base64-png --save`
or
`yarn add react-native-image-base64-png`


## Installation

`$ react-native link react-native-image-base64-png`

## Usage
```javascript
import ImgToBase64 from 'react-native-image-base64-png';

ImgToBase64.getBase64String('file://youfileurl')
  .then(base64String => doSomethingWith(base64String))
  .catch(err => doSomethingWith(err));
```

## Changes made

This package has been updated based on [this](https://github.com/Snapp-FidMe/react-native-image-base64/issues/4) thread.

Simply put, `android/src/java/RNImgToBase64Module.java` has been changed as follows:
```java
bitmap.compress(Bitmap.CompressFormat.JPEG, 80, byteArrayOutputStream);
```
To:
```java
bitmap.compress(Bitmap.CompressFormat.PNG, 80, byteArrayOutputStream);
```

I have also added types in `index.d.ts`:
```typescript
declare module 'react-native-image-base64' {
  export default class ImgToBase64 {
    static getBase64String(filePath: string): Promise<string>;
  }
}
```

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