turbojpeg-python
Python bindings for libjpeg-turbo using pybind11. It's using Version 3 of the TurboJPEG C API.
It implements the three functions transform, compress and decompress. For more details see the function docstrings or the TurboJPEG C API docs https://rawcdn.githack.com/libjpeg-turbo/libjpeg-turbo/main/doc/html/group___turbo_j_p_e_g.html
Install
pip install turbojpeg
Example
Rotate JPEG file losslessly by 90 degrees.
import turbojpeg
with open("image.jpg", "rb") as fr:
img_data = fr.read()
# lossless rotation. fails if lossless rotation is not possible
# for example when the image dimensions are not multiples of 16
img_data_rot = turbojpeg.transform(img_data, op=turbojpeg.OP.ROT90)
with open("image-rotated.jpg", "xb") as fw:
fw.write(img_data_rot)
Save random image as JPEG with arithmetic coding.
import numpy as np
import turbojpeg
arr = np.random.randint(0, 256, (256, 256, 3), dtype=np.uint8) # random color image
quality = 90
result = turbojpeg.compress(arr, quality, turbojpeg.SAMP.Y420, arithmetic=True)
with open("arithmetic.jpg", "xb") as fw:
fw.write(result)
Build
The Python setup.py expects the libjpeg-turbo binaries in libjpeg-turbo-build. You can either build it yourself or download precompiled binaries. For more details see https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/BUILDING.md.
GitHub actions CI builds wheels for Windows 32 and 64-bit, manylinux 64-bit, musllinux 64-bit and MacOS 64-bit. 32-bit Linux builds fail due some weird NASM error. Not all wheels are tested, since some of the test dependencies are not available for all platforms.
Run tests
python -m unittest discover -s tests
Metadata
Release files for turbojpeg-rpi 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| turbojpeg_rpi-0.0.3-cp311-cp311-manylinux_2_34_aarch64.whl | CPython 3.11 | CPython 3.11 | Linux glibc 2.34+ ARM64 | Details for turbojpeg_rpi-0.0.3-cp311-cp311-manylinux_2_34_aarch64.whl |
Release files / turbojpeg_rpi-0.0.3-cp311-cp311-manylinux_2_34_aarch64.whl
| Download URL | turbojpeg_rpi-0.0.3-cp311-cp311-manylinux_2_34_aarch64.whl |
|---|---|
| Size | 550.8 kB |
| Tags | CPython 3.11 Linux glibc 2.34+ ARM64 |
|
SHA-256 checksum How to use checksums |
b691a5876f05d59bf51fa9f0f300f624338b4b2297a951b31ffb0ddbe14f27b5
|
|
BLAKE2b-256 checksum How to use checksums |
ba70aea165178c5ba021fcb28faa80c1ebb93c19120b533d72ff87483c08a3b5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.13
|
Security for turbojpeg-rpi 0.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.