# BlurHash-AVIF
A Python library extending the Python BlurHash implementation to generate BlurHash strings and PNG data URLs for AVIF images.
**Disclaimer:** This is an unofficial extension and has no affiliation with the original BlurHash developers. All credit for the BlurHash concept and implementation goes to its creators.
## Table of Contents
1. [Installation](#installation)
2. [Features](#features)
3. [Requirements](#requirements)
4. [Usage](#usage)
5. [Troubleshooting](#troubleshooting)
6. [Contributing](#contributing)
7. [Attribution](#attribution)
8. [License](#license)
## Installation
Install the library using pip:
```bash
pip install blurhash-avif
```
## Features
- Generate BlurHash strings from AVIF images
- Create base64-encoded PNG data URLs from AVIF images
- Maintain image aspect ratio during processing
- Support RGB mode images
- Optimize image loading for improved website performance
## Requirements
- Python 3.x
- Pillow (PIL) library with AVIF support
- NumPy library
- base64 library
- blurhash library
## Usage
The library provides six main functions:
1. `generate_blurhash_from_avif`: Create a BlurHash string from an AVIF image.
2. `generate_png_data_url_from_avif`: Generate a base64-encoded PNG data URL from an AVIF image.
3. `generate_blurhash_and_data_url_from_avif`: Produce both a BlurHash string and a PNG data URL.
4. `batch_generate_blurhash_from_avif`: Generates BlurHash strings for all AVIF images in a given directory.
5. `batch_generate_png_data_url_from_avif`: Generates base64-encoded PNG data URLs for all AVIF images in a given directory.
6. `batch_generate_blurhash_and_data_url_from_avif`: Generates BlurHash strings and base64-encoded PNG data URLs for all AVIF images in a given directory.
### Example Usage
```python
from blurhash_avif import (
generate_blurhash_from_avif,
generate_png_data_url_from_avif,
generate_blurhash_and_data_url_from_avif,
batch_generate_blurhash_from_avif,
batch_generate_png_data_url_from_avif,
batch_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")
# Batch generate BlurHash strings
directory = "path/to/your/images"
blurhash_dict = batch_generate_blurhash_from_avif(directory)
print(blurhash_dict)
# Batch generate PNG data URLs
data_url_dict = batch_generate_png_data_url_from_avif(directory)
print(data_url_dict)
# Batch generate BlurHash strings and PNG data URLs
blurhash_dict, data_url_dict = batch_generate_blurhash_and_data_url_from_avif(directory)
print(blurhash_dict)
print(data_url_dict)
```
## Troubleshooting
If you encounter issues with Pillow's AVIF support, try:
```bash
pip uninstall pillow
pip install "pillow[avif]"
```
you man need to install the `aviflib` library.
To install the required `aviflib` library, follow these steps:
**On macOS (using Homebrew):**
```bash
brew install libavif
```
**On Ubuntu/Debian:**
```bash
sudo apt-get install libavif-dev
```
**On windows**
```bash
pip install aom
```
or
**On windows (vcpkg)**
```bash
vcpkg install libavif
```
## Contributing
We welcome contributions! To contribute:
1. Fork the repository
2. Create your feature branch
3. Commit your changes
4. Push to the branch
5. Open a pull request
## Attribution
This package extends the Python BlurHash library. BlurHash was originally created by Dag Ă…gren for Wolt. The BlurHash algorithm and official implementations are available at the [BlurHash GitHub repository](https://github.com/woltapp/blurhash).
## License
This project is licensed under the Apache License, Version 2.0 with important additional terms, including specific commercial use conditions. Users are strongly advised to read the full [LICENSE](LICENSE) file carefully before using, modifying, or distributing this work. The additional terms contain crucial information about liability, data collection, indemnification, and commercial usage requirements that may significantly affect your rights and obligations.
---
Keywords: BlurHash, AVIF, image processing, Python, base64, PNG, data URL, image optimization, web performance, placeholder images
Raw data
{
"_id": null,
"home_page": "https://github.com/ZuidVolt/blurhash-avif",
"name": "blurhash-avif",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": "blurhash avif image processing",
"author": "ZuidVolt",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/7c/58/c0001d0e45adc7b37820ac5a0fd502b2bdb3db5c6e2608226038fb9a7b88/blurhash_avif-0.7.1.tar.gz",
"platform": null,
"description": "\n# BlurHash-AVIF\n\nA Python library extending the Python BlurHash implementation to generate BlurHash strings and PNG data URLs for AVIF images.\n\n**Disclaimer:** This is an unofficial extension and has no affiliation with the original BlurHash developers. All credit for the BlurHash concept and implementation goes to its creators.\n\n## Table of Contents\n\n1. [Installation](#installation)\n2. [Features](#features)\n3. [Requirements](#requirements)\n4. [Usage](#usage)\n5. [Troubleshooting](#troubleshooting)\n6. [Contributing](#contributing)\n7. [Attribution](#attribution)\n8. [License](#license)\n\n## Installation\n\nInstall the library using pip:\n\n```bash\npip install blurhash-avif\n```\n\n## Features\n\n- Generate BlurHash strings from AVIF images\n- Create base64-encoded PNG data URLs from AVIF images\n- Maintain image aspect ratio during processing\n- Support RGB mode images\n- Optimize image loading for improved website performance\n\n## Requirements\n\n- Python 3.x\n- Pillow (PIL) library with AVIF support\n- NumPy library\n- base64 library\n- blurhash library\n\n## Usage\n\nThe library provides six main functions:\n\n1. `generate_blurhash_from_avif`: Create a BlurHash string from an AVIF image.\n2. `generate_png_data_url_from_avif`: Generate a base64-encoded PNG data URL from an AVIF image.\n3. `generate_blurhash_and_data_url_from_avif`: Produce both a BlurHash string and a PNG data URL.\n4. `batch_generate_blurhash_from_avif`: Generates BlurHash strings for all AVIF images in a given directory.\n5. `batch_generate_png_data_url_from_avif`: Generates base64-encoded PNG data URLs for all AVIF images in a given directory.\n6. `batch_generate_blurhash_and_data_url_from_avif`: Generates BlurHash strings and base64-encoded PNG data URLs for all AVIF images in a given directory.\n\n### Example Usage\n\n```python\nfrom blurhash_avif import (\n generate_blurhash_from_avif,\n generate_png_data_url_from_avif,\n generate_blurhash_and_data_url_from_avif,\n batch_generate_blurhash_from_avif,\n batch_generate_png_data_url_from_avif,\n batch_generate_blurhash_and_data_url_from_avif,\n)\n\n# Path to your AVIF file\navif_path = \"path/to/your/image.avif\"\n\n# Generate BlurHash string\nblurhash = generate_blurhash_from_avif(avif_path)\nif blurhash:\n print(f\"BlurHash: {blurhash}\")\nelse:\n print(\"Failed to generate BlurHash\")\n\n# Generate PNG data URL\ndata_url = generate_png_data_url_from_avif(avif_path)\nif data_url:\n print(f\"PNG Data URL: {data_url[:50]}...\") # Print first 50 characters\nelse:\n print(\"Failed to generate PNG Data URL\")\n\n# Generate both BlurHash and PNG data URL\nblurhash, data_url = generate_blurhash_and_data_url_from_avif(avif_path)\nif blurhash and data_url:\n print(f\"BlurHash: {blurhash}\")\n print(f\"PNG Data URL: {data_url[:50]}...\") # Print first 50 characters\nelse:\n print(\"Failed to generate BlurHash and PNG Data URL\")\n\n# Batch generate BlurHash strings\ndirectory = \"path/to/your/images\"\nblurhash_dict = batch_generate_blurhash_from_avif(directory)\nprint(blurhash_dict)\n\n# Batch generate PNG data URLs\ndata_url_dict = batch_generate_png_data_url_from_avif(directory)\nprint(data_url_dict)\n\n# Batch generate BlurHash strings and PNG data URLs\nblurhash_dict, data_url_dict = batch_generate_blurhash_and_data_url_from_avif(directory)\nprint(blurhash_dict)\nprint(data_url_dict)\n```\n\n## Troubleshooting\n\nIf you encounter issues with Pillow's AVIF support, try:\n\n```bash\npip uninstall pillow\npip install \"pillow[avif]\"\n```\n\nyou man need to install the `aviflib` library.\n\nTo install the required `aviflib` library, follow these steps:\n\n**On macOS (using Homebrew):**\n\n```bash\nbrew install libavif\n```\n\n**On Ubuntu/Debian:**\n\n```bash\nsudo apt-get install libavif-dev\n```\n\n**On windows**\n\n```bash\npip install aom\n```\n\nor\n\n**On windows (vcpkg)**\n\n```bash\nvcpkg install libavif\n```\n\n## Contributing\n\nWe welcome contributions! To contribute:\n\n1. Fork the repository\n2. Create your feature branch\n3. Commit your changes\n4. Push to the branch\n5. Open a pull request\n\n## Attribution\n\nThis package extends the Python BlurHash library. BlurHash was originally created by Dag \u00c5gren for Wolt. The BlurHash algorithm and official implementations are available at the [BlurHash GitHub repository](https://github.com/woltapp/blurhash).\n\n## License\n\nThis project is licensed under the Apache License, Version 2.0 with important additional terms, including specific commercial use conditions. Users are strongly advised to read the full [LICENSE](LICENSE) file carefully before using, modifying, or distributing this work. The additional terms contain crucial information about liability, data collection, indemnification, and commercial usage requirements that may significantly affect your rights and obligations.\n\n---\n\nKeywords: BlurHash, AVIF, image processing, Python, base64, PNG, data URL, image optimization, web performance, placeholder images\n",
"bugtrack_url": null,
"license": "Apache Software License",
"summary": "A library to generate BlurHash and PNG data URLs for AVIF images",
"version": "0.7.1",
"project_urls": {
"Changelog": "https://github.com/ZuidVolt/blurhash-avif/releases",
"Documentation": "https://github.com/ZuidVolt/blurhash-avif/blob/main/README.md",
"Homepage": "https://github.com/ZuidVolt/blurhash-avif",
"Issue Tracker": "https://github.com/ZuidVolt/blurhash-avif/issues",
"source:": "https://github.com/ZuidVolt/blurhash-avif"
},
"split_keywords": [
"blurhash",
"avif",
"image",
"processing"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "0918dfcf194878e81ef8a0409d94409b92be84f5486f6fdabcec933d626678e5",
"md5": "48a4aa88692495caa00e105989ef43f5",
"sha256": "abd125fb46604a5cb00edfb3d410be3eb636e914c9326c7fa95c0b0d9b70c218"
},
"downloads": -1,
"filename": "blurhash_avif-0.7.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "48a4aa88692495caa00e105989ef43f5",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 13229,
"upload_time": "2024-09-06T08:18:43",
"upload_time_iso_8601": "2024-09-06T08:18:43.671822Z",
"url": "https://files.pythonhosted.org/packages/09/18/dfcf194878e81ef8a0409d94409b92be84f5486f6fdabcec933d626678e5/blurhash_avif-0.7.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "7c58c0001d0e45adc7b37820ac5a0fd502b2bdb3db5c6e2608226038fb9a7b88",
"md5": "3220c2cdf488f24fd551e59019745cff",
"sha256": "f00e19e37abd2918e4f325c14af62a2fa99ddaf1bb3df272baae6fa11ff99505"
},
"downloads": -1,
"filename": "blurhash_avif-0.7.1.tar.gz",
"has_sig": false,
"md5_digest": "3220c2cdf488f24fd551e59019745cff",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 11088,
"upload_time": "2024-09-06T08:18:45",
"upload_time_iso_8601": "2024-09-06T08:18:45.141494Z",
"url": "https://files.pythonhosted.org/packages/7c/58/c0001d0e45adc7b37820ac5a0fd502b2bdb3db5c6e2608226038fb9a7b88/blurhash_avif-0.7.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-06 08:18:45",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "ZuidVolt",
"github_project": "blurhash-avif",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "blurhash-avif"
}