Functions
register
Register image processing functions with Jinja2 environment.
register
def register(env: Environment, site: Site) -> None
Register image processing functions with Jinja2 environment.
Parameters 2
| Name | Type | Default | Description |
|---|---|---|---|
env |
Environment |
— | |
site |
Site |
— |
image_url
Generate image URL with optional parameters.
image_url
def image_url(path: str, base_url: str, width: int | None = None, height: int | None = None, quality: int | None = None) -> str
Generate image URL with optional parameters.
Parameters 5
| Name | Type | Default | Description |
|---|---|---|---|
path |
str |
— | Image path |
base_url |
str |
— | Base URL for site |
width |
int | None |
None |
Target width (optional) |
height |
int | None |
None |
Target height (optional) |
quality |
int | None |
None |
JPEG quality (optional) |
Returns
Image URL with query parametersstr
—
image_dimensions
Get image dimensions (width, height).
Requires Pillow (PIL) library. Returns None if not available…
image_dimensions
def image_dimensions(path: str, root_path: Path) -> tuple[int, int] | None
Get image dimensions (width, height).
Requires Pillow (PIL) library. Returns None if not available or file not found.
Parameters 2
| Name | Type | Default | Description |
|---|---|---|---|
path |
str |
— | Image path |
root_path |
Path |
— | Site root path |
Returns
Tuple of (width, height) or Nonetuple[int, int] | None
—
image_srcset
Generate srcset attribute for responsive images.
image_srcset
def image_srcset(image_path: str, sizes: list[int]) -> str
Generate srcset attribute for responsive images.
Parameters 2
| Name | Type | Default | Description |
|---|---|---|---|
image_path |
str |
— | Base image path |
sizes |
list[int] |
— | List of widths (e.g., [400, 800, 1200]) |
Returns
srcset attribute valuestr
—
image_srcset_gen
Generate srcset attribute with default sizes.
image_srcset_gen
def image_srcset_gen(image_path: str, sizes: list[int] | None = None) -> str
Generate srcset attribute with default sizes.
Parameters 2
| Name | Type | Default | Description |
|---|---|---|---|
image_path |
str |
— | Base image path |
sizes |
list[int] | None |
None |
List of widths (default: [400, 800, 1200, 1600]) |
Returns
srcset attribute valuestr
—
image_alt
Generate alt text from filename.
Converts filename to human-readable alt text by:
- Removing exten…
image_alt
def image_alt(filename: str) -> str
Generate alt text from filename.
Converts filename to human-readable alt text by:
- Removing extension
- Replacing hyphens/underscores with spaces
- Capitalizing words
Parameters 1
| Name | Type | Default | Description |
|---|---|---|---|
filename |
str |
— | Image filename |
Returns
Alt text suggestionstr
—
image_data_uri
Convert image to data URI for inline embedding.
image_data_uri
def image_data_uri(path: str, root_path: Path) -> str
Convert image to data URI for inline embedding.
Parameters 2
| Name | Type | Default | Description |
|---|---|---|---|
path |
str |
— | Image path |
root_path |
Path |
— | Site root path |
Returns
Data URI stringstr
—