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

pgmjs

v1.1.6

Published

A library to work with PGM files in Javascript.

Downloads

202

Readme

pgmjs

A pure Javascript library to work with PGM files. Supports both plain and raw PGM. Also supports adding color filters to your images.

I wrote this to convert PGM images from the Game Boy Camera to PNG. Confusingly, these images are sometimes in raw PGM and sometimes in plain PGM format. I decided to write a plain JS library because the only available options used underlying native modules which are cumbersome to work with.

Feature requests and pull requests are very welcome. At the moment I only implemented the functionality I myself needed.

Fun note: filters could be added in the PNG output step of writePngFromPgm().

API

readPgm(filePath)

For a given file path, returns an object describing the PGM data.

Arguments

  • filePath: Path of the file to read

Returns

A Promise containing an Object with:

  • signature: P5 or P2 (or invalid)
  • width: The image width
  • height: The image height
  • maxval: The maximum gray value
  • pixels: An array with the individual pixel values as numbers from 0 to maxval, from top
  • left to bottom right, rows first then columns

writePngFromPgm(pgmData, outPath, colorMasks)

For a given PGM file, convers it to PNG and writes that as a file.

Arguments

  • pgmData: An object as returned by readPgm()
  • outPath: The path to write the PNG file to
  • colorMasks: An array of color masks, so for example [[0,0,1], [0.9,0,0.9]]. See below.

Returns

A Promise.

Color Masks

Color masks allow you to add filters (think Instagram color filters) to your exported images. A color mask looks like this:

[1, 0, 1] // R, G, B

These values basically scale the red, green, and blue output values, so an image with the above mask applied will have a purple tint.

Things become more interesting when you apply multiple color masks. For example:

[[0,0,1], [1,0,1], [1,0,0], [1,1,0]]

An image with this color mask applied will have a nice blue-purple-red-yellow color palette. This works quite simply — the image's brightness values are segmented into 4 (the number of masks) buckets, and each bucket is multiplied by its respective color mask. So in this example, dark segments will be tinted blue, medium dark segments purple, brighter segments red, and the brightest segments yellow. This gives the images a nice look. The above array of color masks is the format that writePngFromPgm() takes its color masks in.

Tests

There is only a very simple test in test/test.js which runs the PNG conversion on both a raw PGM and plain PGM picture.

Credits

By Vlad-Stefan Harbuz.

PNG conversion using pngjs by Luke Page.

Football image in test/test_p5.pgm by Sven Dahlstrand.