0.2.0 ā€¢ Published 5 months ago

string-to-image v0.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

šŸ¤” 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!'