Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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!
- Host: GitHub
- URL: https://github.com/apteryxxyz/string-to-image
- Owner: apteryxxyz
- Created: 2023-12-06T15:20:28.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-12-06T18:15:23.000Z (about 1 year ago)
- Last Synced: 2024-11-11T23:54:48.857Z (about 1 month ago)
- Language: TypeScript
- Homepage: https://npmjs.com/string-to-image
- Size: 107 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
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
# 🤔 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!'
```