# stb — Single-Header C Libraries for Graphics, Audio and More > A collection of public-domain single-file C libraries by Sean Barrett covering image loading, font rendering, noise generation, and more. ## Install Save in your project root: # stb — Single-Header C Libraries for Graphics, Audio and More ## Quick Use ```c // Just drop the header and define the implementation in ONE .c file #define STB_IMAGE_IMPLEMENTATION #include "stb_image.h" int w, h, channels; unsigned char *img = stbi_load("photo.png", &w, &h, &channels, 0); // use img... stbi_image_free(img); ``` ## 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_JPEG` to 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. ## Sources - https://github.com/nothings/stb - https://github.com/nothings/stb/blob/master/docs/stb_howto.txt --- Source: https://tokrepo.com/en/workflows/asset-34a88962 Author: AI Open Source