Skip to main content

A simple package for fast JPEG encoding and decoding.

Project description

This project is in no way affiliated with the libjpeg-turbo project.

simplejpeg

simplejpeg is a simple package based on recent versions of libturbojpeg for fast JPEG encoding and decoding.

Why another library?

Pillow and OpenCV are excellent options for handling JPEG images and a variety of other formats.

If all you want is to read or write a couple of images and don’t worry about the details, this package is not for you.

Keep reading if you care about speed and want more control over how your JPEGs are handled.

These are the reasons why I started making this:

  1. Pillow is very slow compared to OpenCV.

  2. Pillow only accepts streams as input. Images in memory have to be wrapped in BytesIO or similar. This adds to the slowness.

  3. OpenCV is gigantic, only accepts Numpy arrays as input, and returns images as BGR instead of RGB.

  4. Recent versions of libturbojpeg offer impressive speed gains on modern processors. Linux distributions and libraries tend to ship very old versions.

This library is especially for you if you need:

  1. Speed.

  2. Read and write directly from/to memory.

  3. Advanced features of the underlying library.

Usage

This library provides four functions:

decode_jpeg_header, decode_jpeg, encode_jpeg, is_jpeg.

Uncompressed image data is stored as numpy arrays. Decoding functions can accept any Python object that supports the buffer protocol, like array, bytes, bytearray, memoryview, etc.

decode_jpeg_header

decode_jpeg_header(
    data: Any,
    min_height: SupportsInt=0,
    min_width: SupportsInt=0,
    min_factor: SupportsFloat=1,
)

Decode only the header of a JPEG image given as JPEG (JFIF) data from memory. Accepts any input that supports the buffer protocol. This is very fast on the order of 100000+ images per second. Returns height and width in pixels of the image when decoded, and colorspace and subsampling as string.

  • data: JPEG data in memory; must support buffer interface (e.g., bytes, memoryview)

  • min_height: minimum height in pixels of the decoded image; values <= 0 are ignored

  • min_width: minimum width in pixels of the decoded image; values <= 0 are ignored

  • min_factor: minimum downsampling factor when decoding to smaller size; factors smaller than 2 may take longer to decode

  • returns: (height: int, width: int, colorspace: str, color subsampling: str)

decode_jpeg

def decode_jpeg(
    data: SupportsBuffer,
    colorspace: Text='RGB',
    fastdct: Any=True,
    fastupsample: Any=True,
    min_height: SupportsInt=0,
    min_width: SupportsInt=0,
    min_factor: SupportsFloat=1,
)

Decode a JPEG image given as JPEG (JFIF) data from memory. Accepts any input that supports the buffer protocol. Returns the image as numpy array in the requested colorspace.

  • data: JPEG data in memory; must support buffer interface (e.g., bytes, memoryview)

  • colorspace: target colorspace, any of the following: ‘RGB’, ‘BGR’, ‘RGBX’, ‘BGRX’, ‘XBGR’, ‘XRGB’, ‘GRAY’, ‘RGBA’, ‘BGRA’, ‘ABGR’, ‘ARGB’; ‘CMYK’ may only be used for images already in CMYK space

  • fastdct: if True, use fastest DCT method; usually no observable difference

  • fastupsample: if True, use fastest color upsampling method; usually no observable difference

  • min_height: minimum height in pixels of the decoded image; values <= 0 are ignored

  • param min_width: minimum width in pixels of the decoded image; values <= 0 are ignored

  • param min_factor: minimum downsampling factor when decoding to smaller size; factors smaller than 2 may take longer to decode

  • returns: image as numpy.ndarray

encode_jpeg

def encode_jpeg(
        image: numpy.ndarray,
        quality: SupportsInt=85,
        colorspace: Text='RGB',
        colorsubsampling: Text='444',
        fastdct: Any=True,
)

Encode an image given as numpy array to JPEG (JFIF) string. Returns JPEG (JFIF) data.

  • image: uncompressed image as numpy array

  • quality: JPEG quantization factor; 0-100, higher equals better quality

  • colorspace: source colorspace; one of ‘RGB’, ‘BGR’, ‘RGBX’, ‘BGRX’, ‘XBGR’, ‘XRGB’, ‘GRAY’, ‘RGBA’, ‘BGRA’, ‘ABGR’, ‘ARGB’, ‘CMYK’

  • colorsubsampling: subsampling factor for color channels; one of ‘444’, ‘422’, ‘420’, ‘440’, ‘411’, ‘Gray’.

  • fastdct: If True, use fastest DCT method; usually no observable difference

  • returns: bytes object of encoded image as JPEG (JFIF) data

is_jpeg

def is_jpeg(data: SupportsBytes)

Check whether a bytes object (or similar) contains JPEG (JFIF) data.

  • data: JPEG (JFIF) data

  • returns: True if JPEG

Project details


Download files

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

Source Distribution

simplejpeg-1.2.5.tar.gz (1.2 MB view details)

Uploaded Source

Built Distributions

simplejpeg-1.2.5-cp37-cp37m-manylinux1_x86_64.whl (271.3 kB view details)

Uploaded CPython 3.7m

simplejpeg-1.2.5-cp37-cp37m-manylinux1_i686.whl (267.1 kB view details)

Uploaded CPython 3.7m

simplejpeg-1.2.5-cp36-cp36m-manylinux1_x86_64.whl (271.5 kB view details)

Uploaded CPython 3.6m

simplejpeg-1.2.5-cp36-cp36m-manylinux1_i686.whl (267.4 kB view details)

Uploaded CPython 3.6m

simplejpeg-1.2.5-cp35-cp35m-manylinux1_x86_64.whl (270.0 kB view details)

Uploaded CPython 3.5m

simplejpeg-1.2.5-cp35-cp35m-manylinux1_i686.whl (266.0 kB view details)

Uploaded CPython 3.5m

File details

Details for the file simplejpeg-1.2.5.tar.gz.

File metadata

  • Download URL: simplejpeg-1.2.5.tar.gz
  • Upload date:
  • Size: 1.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.0.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.7.0

File hashes

Hashes for simplejpeg-1.2.5.tar.gz
Algorithm Hash digest
SHA256 5dc580ff1622e30eb917d3ee517660f668757420b1284eb0a6bedbe761ba1429
MD5 6001b653ad2ca89c72379633944a5c25
BLAKE2b-256 3ecdd6482212375434a53d0a5d301ac300d73be5d5256902d0312b543a76d289

See more details on using hashes here.

File details

Details for the file simplejpeg-1.2.5-cp37-cp37m-manylinux1_x86_64.whl.

File metadata

  • Download URL: simplejpeg-1.2.5-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 271.3 kB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.0.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.7.0

File hashes

Hashes for simplejpeg-1.2.5-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 2f2f67f59a66dec26160860f9189fbab0b8b65fdc087ec5dcf15d85f239dcf43
MD5 7bd4e781c852c74b07584c5f31228509
BLAKE2b-256 f723217e460e2c0edbabf3f3fd0b312690590295eca1f5e6d56d4381e737c577

See more details on using hashes here.

File details

Details for the file simplejpeg-1.2.5-cp37-cp37m-manylinux1_i686.whl.

File metadata

  • Download URL: simplejpeg-1.2.5-cp37-cp37m-manylinux1_i686.whl
  • Upload date:
  • Size: 267.1 kB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.0.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.7.0

File hashes

Hashes for simplejpeg-1.2.5-cp37-cp37m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 c284e767fe7e96e23f67754b61fb62ff0687bca610e26905b57dce3c5d285429
MD5 bb3e85b65365ba3f494677e160245258
BLAKE2b-256 623a1f24fc4b6c00ac8a7f58b5732fc7784d54950ea96f8fb4fb5fcf18706479

See more details on using hashes here.

File details

Details for the file simplejpeg-1.2.5-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

  • Download URL: simplejpeg-1.2.5-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 271.5 kB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.0.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.7.0

File hashes

Hashes for simplejpeg-1.2.5-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 31e3f18d1012a5560a1199d22e0266757092ebce7bcbb30c1355e1c2489aa34a
MD5 edf4c62bc20ce7b7c5692c87ae5632b0
BLAKE2b-256 d7f486f45ab89e593ed83a5c1047c21dfb547a0103204c5fc6ec3ba42424335a

See more details on using hashes here.

File details

Details for the file simplejpeg-1.2.5-cp36-cp36m-manylinux1_i686.whl.

File metadata

  • Download URL: simplejpeg-1.2.5-cp36-cp36m-manylinux1_i686.whl
  • Upload date:
  • Size: 267.4 kB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.0.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.7.0

File hashes

Hashes for simplejpeg-1.2.5-cp36-cp36m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 53abd6951192dfbb2f8a3764b8fc95ce1beac44c43969c6970fe6f249f4813e6
MD5 03b68575aecf81d34ff71613face8300
BLAKE2b-256 abf4ad1ffffa4db0cae96da97b8460c08ae6528b29180f1695bd53a7a0c58957

See more details on using hashes here.

File details

Details for the file simplejpeg-1.2.5-cp35-cp35m-manylinux1_x86_64.whl.

File metadata

  • Download URL: simplejpeg-1.2.5-cp35-cp35m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 270.0 kB
  • Tags: CPython 3.5m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.0.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.7.0

File hashes

Hashes for simplejpeg-1.2.5-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 86c3d7dc7d1006425c13f85ab5dc74712a94f9c48397b689abf329b54741abaf
MD5 56fe698132ce2438b55f81288ee9900e
BLAKE2b-256 9450f7f3417044adcfaf9e145ee52fbbb77cbb2f8f4c6f58d01ef2e2bacdf9b9

See more details on using hashes here.

File details

Details for the file simplejpeg-1.2.5-cp35-cp35m-manylinux1_i686.whl.

File metadata

  • Download URL: simplejpeg-1.2.5-cp35-cp35m-manylinux1_i686.whl
  • Upload date:
  • Size: 266.0 kB
  • Tags: CPython 3.5m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.0.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.7.0

File hashes

Hashes for simplejpeg-1.2.5-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 e821a5d71926d0e56af6d3c02d1787e8153c3e975fb55be11fe525f662ce9c4b
MD5 8ef2f165a95585a3c865b295f5fc7817
BLAKE2b-256 cb4f6d4482be121f229628c88c790dba6cace75f81c2602a78fb41298d56e7f9

See more details on using hashes here.

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