Skip to main content

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

Project description

jpeglib

PyPI version Documentation Status

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

pip3 install jpeglib

Usage

DCT

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

import jpeglib
im = jpeglib.JPEG("input.jpeg") # load metadata
Y,CbCr,qt = im.read_dct() # load data

You get luminance DCT, chrominance DCT and quantization tables.

Write the DCT coefficients back to a file with

im.write_dct("output.jpeg", Y, CbCr) # write data

You can also write the read-write sequence using with statement

with jpeglib.JPEG("input.jpeg") as im:
  Y,CbCr,qt = im.read_dct()
  # modify the DCT coefficients
  im.write_dct("output.jpeg", Y, CbCr)

Spatial (RGB)

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

im = jpeglib.JPEG("input.jpeg")
rgb = im.read_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", spatial)

Here 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.set_libjpeg.version('6b')

Currently jpeglib supports the most popular versions 6b and 8d. Their source codes is baked inside the package and thus distributed with it, avoiding external dependency.

Credits

Developed by Martin Benes.

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.5.5.tar.gz (506.7 kB view hashes)

Uploaded Source

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