module

MJ::Pixelize

Pixel-art restyle via Nano Banana 2 (google:4@3), with optional transparency keying and an optional deterministic pixel-perfect "snap" pass.

Stage 1 (the look): the AI redraws the image as 8-bit / 16-bit pixel art — driven by the style prompt, NOT by numeric knobs. Requires the current model (4@3/4@2); the old google:4@1 refuses restyles. Stage 2 (optional authenticity): downscale to a true grid + quantize to N colours + nearest upscale. Works cleanly here precisely because Stage 1 already drew pixel-art forms. Uses ImageMagick (magick).

Constants

CHROMA = [255, 0, 255]

Class methods

build_prompt(spec : PixelSpec) : String
Source
finish(redraw_bytes : Bytes, spec : PixelSpec) : StumpyPNG::Canvas

Stage 2: turn a raw redraw into the final sprite (snap + background keying).

Source
key_transparent(canvas : StumpyPNG::Canvas, spec : PixelSpec) : StumpyPNG::Canvas

Key the flat magenta field to transparent using the PROP keyer, so pixel-art edges get despilled/defringed and transparent pixels solidified (alpha-bleed). The bare distance key used to leave the chroma colour in edge + transparent pixels, which showed as a magenta outline (and resurrected on downscale). Thresholds/toggles come from the PixelSpec.

Source
redraw(client : RunwareClient, image_bytes : Bytes, spec : PixelSpec) : Bytes

Stage 1: raw AI redraw. Returns the PNG bytes as generated.

Source
snap(src : StumpyPNG::Canvas, grid : Int32, colors : Int32) : StumpyPNG::Canvas

Deterministic pixel-perfect pass via ImageMagick: downscale to grid, quantise to colors (flat, no dither), nearest-upscale back to the canvas size.

Source
style_prompt(style : String) : String
Source