The image controller provides reusable image downloading, decoding, resizing, and caching services.
The goal of this component is to allow higher-level applications to display images without needing to manage HTTP requests, image decoding, or caching logic.
| Component | Description |
|---|---|
| ImageDownloader | Downloads image data from HTTP or HTTPS URLs. |
| ImageCache | Downloads, decodes, resizes, caches, and returns Pillow images. |
| image_errors.py | Image-specific exception classes. |
The image controller provides:
This component requires Pillow.
Install using:
ImageDownloader downloads raw image data.
Features include:
Example:
ImageCache manages downloading, decoding, resizing, and caching.
Images are automatically cached using an LRU eviction policy.
Example:
Repeated requests for the same URL and size return the cached image.
ImageCache.get() returns a Pillow Image.Image object.
The caller may:
The image controller does not depend on any GUI framework.
The image controller may raise:
These exceptions indicate failures while downloading or decoding images.
A CLI component test is provided.
Run from the project root:
Example:
The component test demonstrates:
This controller is intentionally independent of any specific application or user interface.
Responsibilities include:
Responsibilities that belong outside this component include:
Keeping these responsibilities separate allows the image controller to be reused by any higher-level component requiring image support.
Persistent filesystem mechanics are delegated to PersistentCache rather than generalized inside the image package. Image decoding, resizing, and decoded-image LRU policy remain image-specific.