TurboJPEG
raw JSON → 0.0.2.post1 verified Fri May 01 auth: no python
Python bindings for libjpeg-turbo using pybind11, providing fast JPEG compression and decompression with access to lossless crop/scale operations. Current version 0.0.2.post1, requires Python >=3.7. Development is slow with only a few releases.
pip install turbojpeg Common errors
error ModuleNotFoundError: No module named 'turbojpeg' ↓
cause Package not installed or installed in wrong environment.
fix
pip install turbojpeg
error OSError: libturbojpeg.so: cannot open shared object file: No such file or directory ↓
cause libjpeg-turbo shared library not found on system.
fix
Install libjpeg-turbo via system package manager (e.g., apt install libturbojpeg0-dev on Ubuntu).
error AttributeError: module 'turbojpeg' has no attribute 'TurboJPEG' ↓
cause Wrong import path or outdated version where class was named differently.
fix
Use 'from turbojpeg import TurboJPEG' and ensure version >=0.0.2.
Warnings
gotcha The package version 0.0.2.post1 is very early and may have API changes without notice. Not recommended for production. ↓
fix Pin version or monitor for updates.
gotcha Platform compatibility: binary wheels are not provided for all platforms (e.g., aarch64, manylinux2014). You may need to install libjpeg-turbo system-wide or build from source. ↓
fix Install libjpeg-turbo via system package manager (e.g., apt install libjpeg-turbo8-dev) or use Docker.
deprecated The 'decode' method returns a numpy array with HWC format (height, width, channels). Some users expect CHW. ↓
fix Ensure numpy and array handling match expected layout.
Imports
- TurboJPEG
from turbojpeg import TurboJPEG
Quickstart
from turbojpeg import TurboJPEG
import os
# Initialize TurboJPEG
jpeg = TurboJPEG()
# Read JPEG file and decompress
input_file = 'input.jpg'
with open(input_file, 'rb') as f:
jpeg_data = f.read()
img = jpeg.decode(jpeg_data)
# img is a numpy array (height, width, channels)
# Compress back to JPEG
output_file = 'output.jpg'
with open(output_file, 'wb') as f:
f.write(jpeg.encode(img))