A Typst package for creating pixel art directly in your documents. Convert images to pixel art or design custom pixel graphics using simple text maps.
#import "@preview/typixel:0.1.0": *
#set page(width: auto, height: auto, margin: 1cm)
#grid(
columns: 2,
gutter: 10pt,
image("gahag.jpg", width: 5cm),
pixel-image(
read("gahag.jpg", encoding: none),
rows: 32,
shape: square-shape,
width: 5cm,
)
)#import "@preview/typixel:0.1.0": *
#set page(width: auto, height: auto, margin: 1cm)
#pixel-map(
"
....XXX....
...XXXXX...
..XXXXXXX..
.XXXXXXXXX.
XXXXXXXXXXX
",
palette: ("X": red, ".": none),
pixel-size: 10pt
)Convert raw image data to pixel art.
Parameters:
image-data(bytes): Raw image data (e.g. fromread("path", encoding: none))columns(int, default: auto): Number of pixel columnsrows(int, default: auto): Number of pixel rowsscale(float, default: auto): Scale factor for imagecolors(int, default: 64): Number of colors in palettetransparency-char(string, default: "."): Character representing transparencypixel-size(length, default: 5pt): Size of each pixelwidth(length, default: auto): Total width (overrides pixel-size)shape(function, default: square-shape): Shape function for pixelsgap(length, default: 0pt): Gap between pixels
Example:
#pixel-image(
read("logo.png", encoding: none),
columns: 48,
colors: 32,
pixel-size: 6pt,
gap: 1pt,
shape: circle-shape
)Create pixel art from a text grid.
Parameters:
map(string): Multi-line string defining the pixel gridpalette(dictionary): Mapping of characters to colorspixel-size(length, default: 10pt): Size of each pixelwidth(length, default: auto): Total width (overrides pixel-size)shape(function/dictionary, default: square-shape): Shape(s) for pixelsgap(length, default: 0pt): Gap between pixels
Example:
#pixel-map(
"
.OOOOO.
O.....O
O.O.O.O
O.....O
.OOOOO.
",
palette: (
"O": black,
".": white
),
pixel-size: 15pt
)square-shape- Standard square pixelscircle-shape- Circular pixelsrounded-shape- Rounded corner squares (customizable radius)diamond-shape- Diamond/rotated square pixelsstar-shape- Five-pointed star pixelscross-shape- X-shaped pixels (customizable thickness)heart-shape- Heart-shaped pixels
Single shape for all pixels:
#pixel-map(map, palette: palette, shape: circle-shape)Different shapes per character:
#pixel-map(
map,
palette: ("X": red, "O": blue),
shape: (
"X": star-shape,
"O": circle-shape
)
)Custom shape parameters:
#pixel-map(
map,
palette: palette,
shape: (w, h, f) => rounded-shape(
width: w,
height: h,
fill: f,
radius: 30%
)
)#import "@preview/typixel:0.1.0": *
#set page(width: auto, height: auto, margin: 1cm)
#pixel-map(
"ROYGBIV\n" * 7,
palette: (
"R": red,
"O": orange,
"Y": yellow,
"G": green,
"B": blue,
"I": rgb("#4B0082"),
"V": rgb("#8F00FF")
),
width: 200pt,
shape: circle-shape
)#import "@preview/typixel:0.1.0": *
#set page(width: auto, height: auto, margin: 1cm)
#pixel-map(
"
SSSSS
CDCDC
HHHHH
",
palette: (
"S": red,
"C": blue,
"D": green,
"H": purple
),
shape: (
"S": star-shape,
"C": circle-shape,
"D": diamond-shape,
"H": heart-shape
),
pixel-size: 20pt,
gap: 2pt
)#import "@preview/typixel:0.1.0": *
#set page(width: auto, height: auto, margin: 1cm)
// 1. Define your custom shape
#let octagon-shape(width: 0pt, height: 0pt, fill: black) = {
let c = 29.29%
box(width: width, height: height,
polygon(
fill: fill,
(c, 0%), (100% - c, 0%),
(100%, c), (100%, 100% - c),
(100% - c, 100%), (c, 100%),
(0%, 100% - c), (0%, c)
)
)
}
// 2. Use it in pixel-map
#pixel-map(
"
..A..
.AAA.
AAAAA
.AAA.
..A..
",
palette: ("A": blue, ".": none),
pixel-size: 20pt,
shape: octagon-shape
)When converting images using pixel-image, the final output height may not exactly match the original image's height.
This occurs because:
- Pixel art requires an integer number of rows, so the height must be rounded to the nearest whole pixel.
- Pixels are forced to be square (width = height).
This project is distributed under the MIT License. See LICENSE for details.