image-array

0.0.3 • Public • Published

npm version

image-array

Converts images to and from several formats.

Table of contents

Installation

To install the library, run:

$ npm install image-array

or with JSDelivr:

<script src="https://cdn.jsdelivr.net/npm/image-array@latest/file"></script>

Importing

With require:

const Converter = require("image-array");

With import:

import Converter from "image-array";

Usage

Instantiating an Image

import Converter from "image-array";

const image = new Parser(
    [type], // A data type ("grid", "canvas", "dataURL", "path", or "buffer")
    [data] // Data in the predefined format
)

Converting an Image

import Converter from "image-array";
const image = new Converter([type], [data])

const canvas = image.toCanvas({width, height}) // Width and height are optional
const dataURL = image.toDataURL()
const buffer = image.toBuffer()
const grid = image.toGrid([format], [transparency]) // "format" is either "hex" or "rgb"

Output

Writing the image to a file

import Converter from "image-array";
const image = new Converter([type], [data])

image.write('./image.png')

Getting Image Data

import Converter from "image-array";
const image = new Converter([type], [data])

console.log(image.cache) // All stored data for the image, updating as more generative methods are called
// -> { grid, canvas, dataURL, buffer }

Package Sidebar

Install

npm i image-array

Weekly Downloads

3

Version

0.0.3

License

ISC

Unpacked Size

9.39 kB

Total Files

3

Last publish

Collaborators

  • else1f