Skip to main content

A Python library to generate multiple thumbnails from high-resolution images.

Project description

Magic Thumbnail

Magic Thumbnail is a Python library designed to generate multiple thumbnails from high-resolution images. It supports downloading images from URLs or using local image files, handles multiple image sources, and offers advanced logging and parallel processing capabilities.

Features

  • Multiple Image Sources: Process multiple images from URLs or local paths.
  • Flexible Thumbnail Sizes: Specify custom thumbnail dimensions.
  • Advanced Logging: Logs detailed information to both console and log files.
  • Parallel Processing: Utilize multiple threads for faster processing.
  • Extensible Formats: Support for various image formats, configurable via environment variables.

Installation

Install the package using pip:

pip install magic_thumbnail

Usage

1. Set Up Environment Variables

Create a .env file in your project directory with the following variables:

# .env

# Comma-separated list of image URLs or local file paths
IMAGE_SOURCES=https://via.placeholder.com/1200, /path/to/local/image.jpg

# Enable parallel processing (true/false)
ENABLE_PARALLEL=true

# Log file name
LOG_FILE=magic_thumbnail.log

# Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
LOG_LEVEL=INFO

# Supported image formats (comma-separated)
SUPPORTED_FORMATS=jpeg,jpg,png,gif,bmp,tiff,webp

# Ensure there are no spaces around the commas.

2. Example Script

Here's how you can use the magic_thumbnail library in your Python project:

from magic_thumbnail import process_images

def main():
    process_images()

if __name__ == "__main__":
    main()

3. Run the Script

Execute your script:

python example_usage.py

4. Output

Thumbnails will be saved in the specified output directories (url_thumbnails and local_thumbnails). Logs will be written to the console and the specified log file (magic_thumbnail.log).

API Reference

process_images() Processes multiple images based on the IMAGE_SOURCES environment variable. Handles both URLs and local file paths.

  • Parameters: None (configurations are read from environment variables)
  • Returns: None

Configuration

All configurations are managed via environment variables in the .env file.

Environment Variables

IMAGE_SOURCES: Comma-separated list of image URLs or local file paths. ENABLE_PARALLEL: Enable (true) or disable (false) parallel processing. LOG_FILE: Name of the log file. LOG_LEVEL: Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL). SUPPORTED_FORMATS: Comma-separated list of supported image formats.

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any enhancements or bug fixes.

License

This project is licensed under the MIT License. See the LICENSE file for details.

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

magic_thumbnail-0.1.0.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

magic_thumbnail-0.1.0-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file magic_thumbnail-0.1.0.tar.gz.

File metadata

  • Download URL: magic_thumbnail-0.1.0.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.12

File hashes

Hashes for magic_thumbnail-0.1.0.tar.gz
Algorithm Hash digest
SHA256 30a37a28af4d67f23b342627ac09911d87048cc2f8d60578cddde33aafa1b1e9
MD5 02f27e07ca58dedc684a3f5b4cee4104
BLAKE2b-256 f1c9834c0b5d37a53f616b140126ee92773243bbe5ba0bfc39ceab215b8ab1c6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: magic_thumbnail-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.12

File hashes

Hashes for magic_thumbnail-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8a9bd5734ed0f815856aebbfaf5e9f08959d8cbb2ec6382564bccbc3a046010f
MD5 67dc2ee13bb7954734a9253c4488b819
BLAKE2b-256 98fb157c81f3d78fae0a8cb30ac6e7cf37deadab9c36ec04d27c4fc0d3f43fa6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page