Skip to main content

Install

pip install libstb

Python 3.9 or newer. The wheel contains the Python package, the libstb command line tool and the compiled C++ library with its headers, so the same install also serves C++ projects.

Two optional extras: pip install "libstb[numpy]" adds Image.numpy(), imread and imresize (zero-copy views), and pip install "libstb[pillow]" adds Image.to_pil() and Image.from_pil().

Use it from C++​

There are two ways to get the C++ library. You need CMake 3.21 or newer and a C++17 compiler.

From the wheel. pip install libstb, then ask the package where its CMake config lives. python -m libstb --cmake-dir prints that directory, and the recipe below runs it for you:

cmake_minimum_required(VERSION 3.21)
project(app LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)

find_package(Python3 REQUIRED COMPONENTS Interpreter)
execute_process(
COMMAND ${Python3_EXECUTABLE} -m libstb --cmake-dir
OUTPUT_VARIABLE libstb_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE
COMMAND_ERROR_IS_FATAL ANY
)
find_package(libstb CONFIG REQUIRED)

add_executable(app main.cpp)
target_link_libraries(app PRIVATE libstb::libstb)

The wheel carries the whole C++ SDK, and Python can tell you where each part is: stb.get_sdk_dir() is its root (an install prefix, usable as CMAKE_PREFIX_PATH), stb.get_include_dir() holds stb.h and stb/*.hpp, stb.get_lib_dir() the shared library and stb.get_cmake_dir() the CMake config.

In your code, #include "stb.h" is the header you need; the namespace is stb. The core is a shared library, so on Windows stb.dll has to sit next to the program or on PATH.

From source. Let CMake fetch the repository:

include(FetchContent)
FetchContent_Declare(libstb GIT_REPOSITORY https://github.com/MohammadRaziei/libstb.git GIT_TAG master)
FetchContent_MakeAvailable(libstb)

target_link_libraries(app PRIVATE libstb::libstb)