Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/apteryxxyz/string-to-image

Convert strings into PNG images, that can be parsed back to the original string!
https://github.com/apteryxxyz/string-to-image

Last synced: 3 days ago
JSON representation

Convert strings into PNG images, that can be parsed back to the original string!

Awesome Lists containing this project

README

        


Convert strings into PNG images, that can be parsed back to the original string!

npm install string-to-image


package version
total downloads


apteryxxyz followers
string-to-image repo stars

# 🤔 About

`string-to-image` is a simple package that can convert any string into a PNG image, and then parse it back to its original string. This can be useful for storing data in images that can then be uploaded to image hosting sites. Those can then be downloaded and parsed back to the original string, a method of free data storage. They can also be useful for storing data in a way that is not easily readable by humans, or for storing data in a way that is not easily editable by humans.

# 🏓 Table of Contents

- [🤔 About](#-about)
- [🏓 Table of Contents](#-table-of-contents)
- [📩 Installation](#-installation)
- [📖 Documentation](#-documentation)
- [Constructor](#constructor)
- [Methods](#methods)
- [📝 Example](#-example)

# 📩 Installation

```bash
npm install string-to-image
yarn add string-to-image
pnpm add string-to-image
```

```js
import { Image } from "string-to-image";
// OR
const { Image } = require("string-to-image");
```

# 📖 Documentation

## Constructor

```ts
public constructor(data: string | Buffer);
```

The constructor accepts either a `string` or a `Buffer` representing a PNG buffer.

## Methods

### getBuffer

```ts
public async getBuffer(): Promise;
```

The `getBuffer` method will return a `Buffer` representing the PNG buffer of the image. This can be used to write the image to a file, or to upload it to an image hosting site.

### getData

```ts
public async getData(): Promise;
```

The `getData` method will return the original string that was used to create the image. This can be used to parse the image back to the original string.

# 📝 Example

```js
import { writeFile } from "node:fs/promises";
import { Image } from "string-to-image";

const image = new Image("Hello, world!");
const buffer = await image.getBuffer();
await writeFile("image.png", buffer);
```

```js
import { readFile } from "node:fs/promises";
import { Image } from "string-to-image";

const buffer = await readFile("image.png");
const image = new Image(buffer);
const data = await image.getData();
// ^? 'Hello, world!'
```