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 Forlenza — justinforlenza/thumbhash-py
Original ThumbHash algorithm: Evan Wallace — evanw/thumbhash
Project details
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0d2a2811668c8bff63b1f12399851362b6cb81b584b318e40cb2f1e2275af419
|
|
| MD5 |
c2e9d0ee4b68f717e561045ea28021e7
|
|
| BLAKE2b-256 |
6029ceb6a81170b3711199fadcf002889007104a4ac4aa4d531778f27205373d
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bfc39237f9c6285c7d0ce0614842e98ea1611a4d1d7d0d1b7b12502a494549d2
|
|
| MD5 |
369de5af2103cf1157684ee92f38870b
|
|
| BLAKE2b-256 |
f6ae826f3ea76cd9d544509b62e4c9a88432c3beb47045475a5f8232a3d87254
|