Skip to main content

Python envelope for the popular C librarylibjpeg for handling JPEG files.

Project description

PyPI version Commit CI/CD Release CI/CD Documentation Status PyPI downloads Stars Contributors Wheel Status PyPi license Last commit

jpeglib

Python envelope for the popular C library libjpeg for handling JPEG files.

libjpeg offers full control over compression and decompression and exposes DCT coefficients and quantization tables.

Installation

Simply install the package with pip3

pip install jpeglib

:warning: This will install jpeglib together with every integrated version of libjpeg, libjpeg-turbo and mozjpeg. For common architectures/OS we provide prebuilt wheels, but installing from source takes couple of minutes to install.

Usage

Import the library in Python 3

import jpeglib

DCT

Get discrete cosine transform (DCT) coefficients and quantization matrices as numpy array

im = jpeglib.read_dct("input.jpeg")
im.Y; im.Cb; im.Cr; im.qt

You get luminance DCT, chrominance DCT and quantization tables.

Write the DCT coefficients back to a file with

im.write_dct("output.jpeg")

Pixel data

Decompress the input.jpeg into spatial representation in numpy array with

im = jpeglib.read_spatial("input.jpeg")
im.spatial

You can specify parameters such as output color space, DCT method, dithering, etc.

Write spatial representation in numpy arrray back to file with

im.write_spatial("output.jpeg")

You can specify input color space, DCT method, sampling factor, output quality, smoothing factor etc.

You can find all the details in the documentation.

libjpeg version

It is possible to choose, which version of libjpeg should be used.

jpeglib.version.set('6b')

Currently jpeglib supports all versions of libjpeg from 6b to 9e, libjpeg-turbo 2.1.0 and mozjpeg 4.0.3. Their source codes is baked inside the package and thus distributed with it, avoiding external dependency.

Get currently used libjpeg version by

version = jpeglib.version.get()

You can also set a libjpeg version for a scope only.

jpeglib.version.set('6b')
im = jpeglib.read_spatial('image.jpeg') # using 6b
with jpeglib.version('9e'):
    im = jpeglib.read_spatial('image.jpeg') # using 9e
im = jpeglib.read_spatial('image.jpeg') # using 6b again

Credits

Developed by Martin Benes, Universität Innsbruck, 2023.

Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jpeglib-0.11.7.tar.gz (8.9 MB view hashes)

Uploaded Source

Built Distributions

jpeglib-0.11.7-cp38-abi3-win_amd64.whl (2.8 MB view hashes)

Uploaded CPython 3.8+ Windows x86-64

jpeglib-0.11.7-cp38-abi3-win32.whl (2.5 MB view hashes)

Uploaded CPython 3.8+ Windows x86

jpeglib-0.11.7-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (14.9 MB view hashes)

Uploaded CPython 3.8+ manylinux: glibc 2.17+ x86-64

jpeglib-0.11.7-cp38-abi3-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl (14.3 MB view hashes)

Uploaded CPython 3.8+ manylinux: glibc 2.12+ i686 manylinux: glibc 2.17+ i686

jpeglib-0.11.7-cp38-abi3-macosx_11_0_arm64.whl (3.5 MB view hashes)

Uploaded CPython 3.8+ macOS 11.0+ ARM64

jpeglib-0.11.7-cp38-abi3-macosx_10_9_x86_64.whl (3.6 MB view hashes)

Uploaded CPython 3.8+ macOS 10.9+ x86-64

jpeglib-0.11.7-cp38-abi3-macosx_10_9_universal2.whl (7.1 MB view hashes)

Uploaded CPython 3.8+ macOS 10.9+ universal2 (ARM64, x86-64)

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page