Skip to main content

A very compact representation of an image placeholder (thumbhash, RGBA-safe fork)

Project description

thash

A Python port of the thumbhash encoder by Evan Wallace.

This is an independently published fork of thumbhash by Justin Forlenza. It fixes the long-standing alpha-channel crash (operator precedence bug in rgba_to_thumb_hash — see upstream issue #1) so that images with transparency no longer raise type tuple doesn't define __round__ method.

Installation

pip install thash

Optionally install with pillow support:

pip install thash[pillow]

Usage

Encode an RGBA array to a ThumbHash:

from thash import rgba_to_thumb_hash


rgba = [100, 85, 15, 255, 100, 84, 32, 255, ...]
width = 100
height = 75

thumb_hash = rgba_to_thumb_hash(width, height, rgba)
# [86, 8, 10, 13, 128, 22, 234, 86, 111, 117, ...]

Open an image with pillow, scale it down to fit in a 100x100 box and encode to a ThumbHash:

from thash import image_to_thumb_hash

thumb_hash = image_to_thumb_hash('image.jpg')
# [86, 8, 10, 13, 128, 22, 234, 86, 111, 117, ...]

Features

This library currently handles the conversion of images to hashes, not the reverse.

Credits

Original Python port: Justin Forlenzajustinforlenza/thumbhash-py

Original ThumbHash algorithm: Evan Wallaceevanw/thumbhash

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

thash-1.0.0.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

thash-1.0.0-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file thash-1.0.0.tar.gz.

File metadata

  • Download URL: thash-1.0.0.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for thash-1.0.0.tar.gz
Algorithm Hash digest
SHA256 0d2a2811668c8bff63b1f12399851362b6cb81b584b318e40cb2f1e2275af419
MD5 c2e9d0ee4b68f717e561045ea28021e7
BLAKE2b-256 6029ceb6a81170b3711199fadcf002889007104a4ac4aa4d531778f27205373d

See more details on using hashes here.

File details

Details for the file thash-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: thash-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for thash-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bfc39237f9c6285c7d0ce0614842e98ea1611a4d1d7d0d1b7b12502a494549d2
MD5 369de5af2103cf1157684ee92f38870b
BLAKE2b-256 f6ae826f3ea76cd9d544509b62e4c9a88432c3beb47045475a5f8232a3d87254

See more details on using hashes here.

Supported by

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