string-to-image
v0.2.0
Published
Convert strings into PNG images, that can be parsed back to the original string!
Downloads
5
Maintainers
Readme
🤔 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
📩 Installation
npm install string-to-image
yarn add string-to-image
pnpm add string-to-image
import { Image } from "string-to-image";
// OR
const { Image } = require("string-to-image");
📖 Documentation
Constructor
public constructor(data: string | Buffer);
The constructor accepts either a string
or a Buffer
representing a PNG buffer.
Methods
getBuffer
public async getBuffer(): Promise<Buffer>;
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
public async getData(): Promise<string>;
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
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);
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!'