npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

simple-image

v1.0.5

Published

Simple image manipulation

Readme

SimpleImage

Simple image manipulation

GitHub release Build Status codecov Codacy Badge

Install

You can install via npm or yarn.

npm

npm install --save simple-image

yarn

yarn add simple-image

Documentation

This documentation is written in TypeScript, however this library works fine in vanilla JavaScript too.

Usage

Creating a SimpleImage

A SimpleImage instance is created asynchronously (beacause we have to wait on image.onload internally), therefore you must await the ready promise.

With dimensions

async function myFn(): void {
  const simpleImage = new SimpleImage(256, 256);

  await simpleImage.ready;

  // Do stuff
}

myFn();

or without async/await:

const simpleImage = new SimpleImage(256, 256);

simpleImage.ready.then(() => {
  // Do stuff
});

With an image element

async function myFn(): void {
  const image: HTMLImageElement = document.getElementById('my-image');

  const simpleImage = new SimpleImage(image);

  await simpleImage.ready;

  // Do stuff
}

myFn();

With a canvas element

async function myFn(): void {
  const canvas: HTMLCanvasElement = document.getElementById('my-canvas');

  const simpleImage = new SimpleImage(canvas);

  await simpleImage.ready;

  // Do stuff
}

myFn();

With a File

const input: HTMLInputElement = document.getElementById('my-input');

input.onchanges = () => {
  const simpleImage = new SimpleImage(input.files[0]);

  await simpleImage.ready;

  // Do stuff
};

With an existing SimpleImage instance

async function myFn(): void {
  const simpleImage = new SimpleImage(256, 256);

  await simpleImage.ready;

  // Do stuff

  const newSimpleImage = new SimpleImage(simpleImage);

  await newSimpleImage.ready;

  // Do stuff
}

myFn();

Methods

Get

There are 4 methods to get a colour at a given position, getRed, getGreen, getBlue, getAlpha.

| Argument | Description | Type | | -------- | -------------------------------------------------------- | ------ | | x | The x coordinate of the pixel you want to the colour for | number | | y | The y coordinate of the pixel you want to the colour for | number |

Set

There are 4 methods to set a colour at a given position, getRed, getGreen, getBlue, getAlpha.

| Argument | Description | Type | | -------- | ------------------------------------------------------------ | ------ | | x | The x coordinate of the pixel you want to set the colour for | number | | y | The y coordinate of the pixel you want to set the colour for | number | | value | Value between 0 and 255 for the colour | number |

getPixel

Gets a pixel at any given coordinate:

| Argument | Description | Type | | -------- | --------------------------------------------- | ------ | | x | The x coordinate of the pixel you want to get | number | | y | The y coordinate of the pixel you want to get | number |

setPixel

Sets a pixel at any given coordinate to match a given pixel:

| Argument | Description | Type | | -------- | --------------------------------------------- | ----------------------------- | | x | The x coordinate of the pixel you want to set | number | | y | The y coordinate of the pixel you want to set | number | | pixel | The pixel you want to match to | SimplePixel |

getPixels

Returns an array of SimplePixel of all the pixels in the image.

setSize

Sets the size of the SimpleImage to the dimensions provided.

| Argument | Description | Type | | -------- | ---------------------------- | ------ | | width | The new width for the image | number | | height | The new height for the image | number |

draw

Draws the SimpleImage to the provided canvas.

| Argument | Description | Type | | -------- | --------------------- | ------------------- | | canvas | The canvas to draw to | HTMLCanvasElement |

toDataUrl

Returns a data url for the SimpleImage.

SimplePixel

An instance of of a pixel within the SimpleImage.

Properties

| Property | Description | Type | | -------- | ----------------------------------------------------------------- | ------ | | x | The x coordinate of the pixel | number | | y | The y coordinate of the pixel | number | | red | Gets/sets the red value for the pixel. Number between 0 and 255 | number | | green | Gets/sets the green value for the pixel. Number between 0 and 255 | number | | blue | Gets/sets the blue value for the pixel. Number between 0 and 255 | number | | alpha | Gets/sets the alpha value for the pixel. Number between 0 and 255 | number |

Methods

setAllFrom

Sets all the colours to match those of a given SimplePixel

| Argument | Description | Type | | -------- | ------------------ | ----------------------------- | | pixel | The pixel to match | SimplePixel |