Bitmaps and typography, in one small library.
libstb decodes, encodes, resizes, edits and draws images, renders text and compresses with zlib, from Python and C++. Nothing has to be installed on the system first.
from pathlib import Pathimport libstb as stbout = Path("out")out.mkdir(exist_ok=True)img = stb.Image.open("astronaut.png")print(f"{img.width}x{img.height}")# Shrink with the default filter, then enlarge the tiny result with each filter by name.tiny = img.resize(64, 64)tiny.write(out / "tiny.png")print(f"{tiny.width}x{tiny.height}")for name in ("nearest", "linear", "cubic", "bspline", "mitchell"):tiny.resize(256, 256, name).write(out / f"{name}.png")
$ ls outtiny.png nearest.png linear.png cubic.png bspline.png mitchell.png
No dependencies
No system libraries and no Python dependencies. The Linux x86-64 wheel is about 1.5 MB, and the C++ library builds from source with CMake.
InstallPython and C++, one library
The same operations in libstb.Image and stb::image. Decode PNG, JPEG, BMP, TGA and GIF, edit, resize, draw and encode.
Resize an imageText that shapes properly
TrueType and CFF fonts with GSUB shaping, bidi reordering and kerning, so Persian and Arabic come out right.
Read the guideFast where it pays
SIMD kernels picked at run time with identical results, the GIL released in Python calls, and big resizes split over threads.
See the numbers