A library to generate BlurHash and PNG data URLs for AVIF images
Project description
blurhash-avif
A Python library to extend the Python Blurhash library to generate BlurHash and PNG data URLs for AVIF images.
Disclaimer: This is an unofficial extension and has no affiliation with the team or community that developed Blurhash. All credit for the original Blurhash concept and implementation goes to the creators of Blurhash.
Installation
You can install the library using pip:
pip install blurhash-avif
Usage
The library provides three main functions:
generate_blurhash_from_avif
: Generates a BlurHash string for an AVIF image.generate_png_data_url_from_avif
: Generates a base64-encoded PNG data URL for an AVIF image.generate_blurhash_and_data_url_from_avif
: Generates both a BlurHash string and a PNG data URL.
Example Usage
from blurhash_avif import generate_blurhash_from_avif, generate_png_data_url_from_avif, generate_blurhash_and_data_url_from_avif
# Path to your AVIF file
avif_path = "path/to/your/image.avif"
# Generate BlurHash string
blurhash = generate_blurhash_from_avif(avif_path)
if blurhash:
print(f"BlurHash: {blurhash}")
else:
print("Failed to generate BlurHash")
# Generate PNG data URL
data_url = generate_png_data_url_from_avif(avif_path)
if data_url:
print(f"PNG Data URL: {data_url[:50]}...") # Print first 50 characters
else:
print("Failed to generate PNG Data URL")
# Generate both BlurHash and PNG data URL
blurhash, data_url = generate_blurhash_and_data_url_from_avif(avif_path)
if blurhash and data_url:
print(f"BlurHash: {blurhash}")
print(f"PNG Data URL: {data_url[:50]}...") # Print first 50 characters
else:
print("Failed to generate BlurHash and PNG Data URL")
Troubleshooting
-
For issues with Pillow's AVIF support, try:
pip uninstall pillow pip install "pillow[avif]"
Attribution
This package is an unofficial extension of the Python Blurhash library. Blurhash was originally created by Dag Ågren for Wolt. The Blurhash algorithm and its official implementations can be found at the official Blurhash GitHub repository.
Licensing
This project is licensed under the Apache License, Version 2.0 with Additional commercial terms. See the LICENSE file for full detail
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
File details
Details for the file blurhash_avif-0.1.0.tar.gz
.
File metadata
- Download URL: blurhash_avif-0.1.0.tar.gz
- Upload date:
- Size: 7.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | efde7d445bc338f1c57428a412f32746bee48532422d79e3360d633635e8f6c8 |
|
MD5 | 07a4104247fea361de69196e39866464 |
|
BLAKE2b-256 | d4158d1c135c746505992e18511825711df5c1bbc6ed53dbbc38f324fff10dbb |
File details
Details for the file blurhash_avif-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: blurhash_avif-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f18e2d6110643c14ad183a4e768c7827120ca668c9e999fb1ccb3f5755e9ff9 |
|
MD5 | 654574a636301f4bfaa48c79311cd8a3 |
|
BLAKE2b-256 | ad50c9dd7bcfe38a4c7de8ae3d53db14502ee9215cd1575f6da3b6e8f7696e79 |