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 🙏

© 2024 – Pkg Stats / Ryan Hefner

qoijs

v1.0.0

Published

Quite-OK Image format encoder/decoder in vanilla javascript

Downloads

2,788

Readme

qoijs

NPM version

"Quite-OK Image format" encoder/decoder in vanilla javascript.

Installing

With npm do:

npm install qoijs

With yarn do:

yarn add qoijs

A compiled version for web browsers is also available on a CDN:

<script src="https://cdn.jsdelivr.net/gh/kchapelier/[email protected]/build/qoijs.min.js"></script>

Public API

Functions

decode(arrayBuffer[, byteOffset[, byteLength[, outputChannels]]])

Decode a QOI file given as an ArrayBuffer.

Returns a literal containing the color data as a TypedArray and all the metadata of the image.

  • arrayBuffer: ArrayBuffer containing the QOI file.
  • byteOffset: Offset to the start of the QOI file in arrayBuffer, defaults to the 0.
  • byteLength: Length of the QOI file in bytes, defaults to the remaining length of arrayBuffer after byteOffset.
  • outputChannels: Number of channels to include in the decoded array (used to remove or add the alpha channel), defaults to the number of channels contained in the QOI file.
const QOI = require('qoijs');

// using fs in node to read the content of a file as a Buffer
const buffer = require('fs').readFileSync('some_image.qoi');
const decodedData = QOI.decode(buffer.buffer, buffer.byteOffset, buffer.byteLength);
// using FileReader to read a file retrieved from a drop event as an ArrayBuffer
const reader = new FileReader();
reader.readAsArrayBuffer(file);
reader.onloadend = function () {
    const arrayBuffer = reader.result;
    const decodedData = QOI.decode(arrayBuffer);
};

encode(colorData, description)

Encode a QOI file.

Returns an ArrayBuffer containing the QOI file content.

  • colorData: Flat array containing the color information for each pixel of the image (from left to right, top to bottom). Must be either an instance of Uint8Array or Uint8ClampedArray.
  • description:
    • width: The width of the image.
    • height: The height of the image.
    • channels: The number of channels of the image.
      • 3: RGB, 4: RGBA
    • colorspace: The color space used to encode the colors in colorData.
      • 0: sRGB with linear alpha, 1: linear
const QOI = require('qoijs');

// encode a 2x2 b/w checkerboard pattern from an arbitrary colorData array
const colorData = new Uint8Array([0,0,0,255, 255,255,255,255, 255,255,255,255, 0,0,0,0]);
const arrayBuffer = QOI.encode(colorData, {
    width: 2,
    height: 2,
    channels: 4,
    colorspace: 0
});
// encode the content of a 2D canvas (ImageData)
const imageData = canvasContext.getImageData(0, 0, canvas.width, canvas.height);
const arrayBuffer = QOI.encode(imageData.data, {
    width: imageData.width,
    height: imageData.height,
    channels: 4,
    colorspace: 0
});

History

1.0.0 (2021-12-27) :

  • First release

How to contribute ?

For new features and other enhancements, please make sure to contact me beforehand, either on Twitter or through an issue on Github.

License

MIT