Skip to content

justinforlenza/thumbhash-py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

thumbhash-py

A Python port of the thumbhash encoder by Evan Wallace

Installation

Install thumbhash with pip

pip install thumbhash

Optionally install with pillow support:

pip install thumbhash[pillow]

Usage

Encode a RGBA array to a ThumbHash

from thumbhash import rgba_to_thumb_hash


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

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

Open an image using pillow, scale down to max dimensions of 100x100 and encode to a ThumbHash

from thumbhash import image_to_thumb_hash

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

Features

As of now this library only handles the conversion of images to hashes, not the reverse.

About

Python port of thumbhash, a very compact representation of an image placeholder

Resources

License

Stars

Watchers

Forks

Languages