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.4.tar.gz (1.2 MB view details)

Uploaded Source

Built Distributions

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

Uploaded CPython 3.7m

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

Uploaded CPython 3.7m

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

Uploaded CPython 3.6m

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

Uploaded CPython 3.6m

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

Uploaded CPython 3.5m

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

Uploaded CPython 3.5m

File details

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

File metadata

  • Download URL: simplejpeg-1.2.4.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.21.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.3

File hashes

Hashes for simplejpeg-1.2.4.tar.gz
Algorithm Hash digest
SHA256 3c30bb5a24c750da1613ef8f37fab079f8778442920badbe8048ca1a7895af73
MD5 7a3b77e3ef0c668284cf6adf4db11031
BLAKE2b-256 435cb2887b1861f88120d62a99c77b0a37e1bf44f585f0fe367c62fcd86d2956

See more details on using hashes here.

File details

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

File metadata

  • Download URL: simplejpeg-1.2.4-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.21.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.3

File hashes

Hashes for simplejpeg-1.2.4-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 8f5f36a3f488dcc9187dbf043a240e146e9341da9797f3de51cd5cf222dcf28d
MD5 2fa6788de9aaf5a1e21495ab4bed72eb
BLAKE2b-256 fdb8ae286f1c70faf375bf89b77f0bd679cb8c144f5c31e1e10dbe6eec266911

See more details on using hashes here.

File details

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

File metadata

  • Download URL: simplejpeg-1.2.4-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.21.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.3

File hashes

Hashes for simplejpeg-1.2.4-cp37-cp37m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 63fb90b05e355182bc13eda1ed215cb30d51c09c738e64c98711c91a665c132c
MD5 967fde73025a022d54e3e99e76c42c4e
BLAKE2b-256 413d16f0baf94ae3ac81f7099e00a5c6c438a96cd01bcabea94c14ebafa3e56d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: simplejpeg-1.2.4-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.21.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.3

File hashes

Hashes for simplejpeg-1.2.4-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 46ae234ecb841ceeffc1eec8e4fd7f7a28cb4dacca912bc262329a3c996603c1
MD5 f65737c5f21755bed1d6a9ad2787f5c9
BLAKE2b-256 5b1b2c0cc2de46ad561cee237b9f6a0dab69be4a266f15aa7465ba8e15501bd3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: simplejpeg-1.2.4-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.21.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.3

File hashes

Hashes for simplejpeg-1.2.4-cp36-cp36m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 5e36a16ad9c23dc700ea0d8dbff0a298830f67729b7df9901783b06c0aafd28c
MD5 bf17a49b3934b71ea0480980d4ae5296
BLAKE2b-256 ace9040dffaa50870397288183eed7b35dafb16b6c8df380252dd0723fa0e2ea

See more details on using hashes here.

File details

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

File metadata

  • Download URL: simplejpeg-1.2.4-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.21.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.3

File hashes

Hashes for simplejpeg-1.2.4-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 aa615b96fa21d06a775298bbc7ad959947d70390c77ee263cc9bd2ac45d71809
MD5 afb59920e5d7634188643fa0ecc1ecc8
BLAKE2b-256 9d5e2073e715317ec57fa6708acb9dd722cfc67f0dc9898d7180f9f061625e54

See more details on using hashes here.

File details

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

File metadata

  • Download URL: simplejpeg-1.2.4-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.21.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.3

File hashes

Hashes for simplejpeg-1.2.4-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 efe8000657362859b16f4b9c43eb3b131d4b3841eb565e359f5d7f32d1e14c19
MD5 36b9b46c6ffc8abe0c3ddd9a711238f1
BLAKE2b-256 bd6f7b1105af6ebd70b265827db56b32b6ebc8f8e14ddc1bbfda813aa08611db

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