Introduction
stb is a collection of about 20 single-file, public-domain C libraries created by Sean Barrett. Each header is entirely self-contained: drop it into your project, define one implementation macro in a single translation unit, and you are done. No build system, no dependencies, no license headaches.
What stb Does
- Loads and writes PNG, JPEG, BMP, TGA, HDR, and PSD images (stb_image / stb_image_write)
- Rasterizes TrueType fonts to bitmaps with optional SDF output (stb_truetype)
- Generates Perlin noise and cellular noise (stb_perlin)
- Provides a stretchy-buffer (dynamic array) for plain C (stb_ds)
- Implements Vorbis audio decoding and DXT texture compression
Architecture Overview
Each library is a single .h file that acts as both interface and implementation. When you #define STB_*_IMPLEMENTATION before including it, the compiler emits the function bodies. Without the define, you get declarations only. This approach eliminates build-system coupling and keeps the libraries trivially embeddable in any C or C++ project.
Self-Hosting & Configuration
- No installation needed — copy the headers you need into your source tree
- Public domain (or MIT licensed, your choice) so no attribution is required
- Configure via preprocessor defines before the include (e.g.,
STBI_NO_JPEGto strip JPEG support) - Works with any C89+ or C++ compiler on any platform
- Compile the implementation in exactly one translation unit to avoid duplicate symbols
Key Features
- Zero external dependencies for every library in the collection
- Battle-tested in thousands of commercial games and applications
- Tiny code size suitable for embedded and WASM targets
- Each library is independent — use only what you need
- Actively maintained with contributions from the community
Comparison with Similar Tools
- lodepng — PNG-only; stb_image handles multiple formats in one header
- FreeType — full-featured font engine but much larger and harder to integrate
- libjpeg / libpng — system libraries requiring separate build and linking
- sokol — similar single-header philosophy but focused on cross-platform graphics APIs
- dr_libs — single-file audio decoders (WAV, MP3, FLAC) that complement stb
FAQ
Q: Why single-header instead of a proper library? A: Single headers eliminate build-system friction. You can integrate stb into any project in seconds without CMake, Meson, or pkg-config.
Q: Is stb_image production quality? A: Yes. It is used in major game engines, Raylib, Dear ImGui backends, and many AAA studios. It has been fuzzed extensively.
Q: Can I use stb in C++ projects? A: Absolutely. The headers compile cleanly as C++ and are regularly tested with GCC, Clang, and MSVC in both C and C++ modes.
Q: What is the license? A: Dual-licensed as public domain (Unlicense) and MIT. Choose whichever works for your legal requirements.