tlc.helpers.image_helper¶
Helpers for working with image data.
Module Contents¶
Classes¶
Class |
Description |
|---|---|
Helper class for image operations. |
API¶
- class ImageHelper¶
Helper class for image operations.
- static get_exif_image_dimensions( ) tuple[int, int]¶
Get the dimensions of an image, accounting for Exif orientation.
- Parameters:
image_url – The URL of the image.
- Returns:
The image dimensions (height, width).
- static get_exif_image_dimensions_from_bytes( ) tuple[int, int]¶
Get the dimensions of an image from bytes, accounting for Exif orientation.
- Parameters:
image_bytes – The bytes of the image.
source – Optional identifier (e.g. a URL) naming the image in the warning emitted when its body is truncated or corrupt but the header dimensions are still readable.
- Returns:
The image dimensions (height, width).
- static open( ) Image¶
Open an image from a path, URL, raw bytes, or an existing PIL image.
This is the canonical way to turn an image-column sample value into a
PIL.Image.Imageregardless of how the column is stored. A table’s image sample can surface either as a path/URL string (file-backed columns) or as an already-loadedPIL.Image.Image(inline columns); passing either — or raw encoded bytes — to this method always yields a usable image. Passing aPIL.Image.Imagereturns it unchanged (apart from an optionalmodeconversion), so it is safe to call defensively in a transform or preprocessing function:from tlc.helpers import ImageHelper def map_fn(sample): image = ImageHelper.open(sample["image"], mode="RGB") return my_transform(image)
String/
Path/tlc.Urlinputs are resolved through the 3LC URL-adapter system, so remote (s3://,gs://) and aliased URLs work, not just local files.- Parameters:
source – A path or URL string, a
Path, atlc.Url, raw encoded image bytes, or an existingPIL.Image.Image.mode – If given, convert the image to this PIL mode (e.g.
"RGB") when it differs from the current mode.
- Returns:
The loaded image as a PIL image.