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

fixelart

v0.0.9

Published

Tool to fix AI-generated pixelart - or just turn your image into pixelart

Downloads

17

Readme

fixelart

A simple utility to fix AI-generated pixelart. Read about how it came to be(and see examples) here or use the playground

| Input | Fixelified outputs | | :------------------------------------------------------------------: | :------------------------------------------------------------------: | | | |

Installation

Using yarn

yarn add fixelart

or npm

npm install fixelart

Usage

The fixImage function accepts an object with the following structure

import { fixImage } from "fixelart";

export interface MinimumData {
  height: number;
  width: number;
  data: Buffer | Array<number>; // This is an array of RGBA values
}

export interface FixOptions {
  // Output pixel width
  outPixWidth: number;
  // Output pixel height
  outPixHeight: number;
  // Strategy to use
  strategy: StrategiesType;
  // Tolerance to be used for mode algorithms
  // e.g. for tolerance=1 rgba(1,1,1,1) would be "equal" to rgba(0,0,0,0) and rgba(2,2,2,2)
  tolerance?: number; // default = 1
  // Whether the output should be shrunk so that an output pixel is actually a pixel
  shrinkOutput?: boolean; // default = false
}

fixImage(png: MinimumData, options: FixOptions)

Strategies

Below you can find all the existing strategies and what they do underneath the hood. PRs are open for more!

  • Strategies.MAJORITY - take the color that occurs the most often in the block
  • Strategies.AVERAGE - take the average(arithmetic mean) of colors in the blocks
  • Strategies.HARMONIC - take the harmonic mean of colors
  • Strategies.GEOMETRIC - take the geometric mean of colors
  • Strategies.MIDRANGE - take the midrange of colors
  • Strategies.QUADRATIC - take the quadratic mean of colors
  • Strategies.CUBIC - take the cubic mean of colors
  • Strategies.ALG(05|10|20|30|40|50|60|70|80|90) - a mix; if a color is making up above X%, then take it, otherwise take the average

Examples

Here's an example usage with pngjs.

import { fixImage } from "fixelart";
import fs from "fs";
import { PNGWithMetadata } from "pngjs";

export const loadPng = (fileName: string): PNGWithMetadata => {
  const file = fs.readFileSync(fileName);

  const png = PNG.sync.read(file);
  return png;
};

export const savePng = (png: PNGWithMetadata, pathToSave: string) => {
  let buff = PNG.sync.write(png);

  fs.writeFileSync(pathToSave, buff);
};

const png = loadPng(path);

const fixedImage = fixImage(png, { outPixWidth, outPixHeight, strategy });

savePng(fixedImage, "./output.png");

You could also use it pretty easily in the browser with Canvas Browser API(todo!) as demonstrated in the demo

Feature requests/Bugs

If you have found a bug or have any ideas for algorithms, or how the tool can improve don't hesitate to file an issue. Please provide the context though!

Interactive examples

All the test images are located inside tests/assets folder

Before running anything, install all the dependencies by running yarn.

There are currently two examples

  1. Generate all the algorithms for an images

This generates all the possible variations of your "fixed" pixelart for every rounding strategy(e.g. average, mean of the colors in the pixel).

Recipe:

yarn example-all-strategies <path_to_image> <pixel_width> <pixel_height>

example:

yarn example-all-strategies ./tests/assets/test-face.png 8 8
  1. Generate all the test images for an algorithm

Recipe:

yarn example-all-images <strategy> <pixel_width> <pixel_height>

example:

yarn example-all-images MEAN 4 4

where

  • strategy is one of the strategies
  • path_to_image is the path to the source image
  • pixel_width and pixel_height are values that indicate how much actual pixels are used in creating a pixel in output pixelart. e.g. if your source image is 1024x1024 and pixel_width and pixel_height are 4, then the output image is going to be a 256-bit pixelart image.