Skip to main content

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:

  1. generate_blurhash_from_avif: Generates a BlurHash string for an AVIF image.
  2. generate_png_data_url_from_avif: Generates a base64-encoded PNG data URL for an AVIF image.
  3. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

blurhash_avif-0.1.0.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

blurhash_avif-0.1.0-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

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

Hashes for blurhash_avif-0.1.0.tar.gz
Algorithm Hash digest
SHA256 efde7d445bc338f1c57428a412f32746bee48532422d79e3360d633635e8f6c8
MD5 07a4104247fea361de69196e39866464
BLAKE2b-256 d4158d1c135c746505992e18511825711df5c1bbc6ed53dbbc38f324fff10dbb

See more details on using hashes here.

File details

Details for the file blurhash_avif-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for blurhash_avif-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2f18e2d6110643c14ad183a4e768c7827120ca668c9e999fb1ccb3f5755e9ff9
MD5 654574a636301f4bfaa48c79311cd8a3
BLAKE2b-256 ad50c9dd7bcfe38a4c7de8ae3d53db14502ee9215cd1575f6da3b6e8f7696e79

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