Module

rendering.template_functions.images

Image processing functions for templates.

Provides 6 functions for working with images in templates. Note: Some functions are stubs for future PIL/Pillow integration.

Functions

register
Register image processing functions with Jinja2 environment.
2 None
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.
5 str
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

str

Image URL with query parameters

image_dimensions
Get image dimensions (width, height). Requires Pillow (PIL) library. Returns None if not available…
2 tuple[int, int] | None
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[int, int] | None

Tuple of (width, height) or None

image_srcset
Generate srcset attribute for responsive images.
2 str
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

str

srcset attribute value

image_srcset_gen
Generate srcset attribute with default sizes.
2 str
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

str

srcset attribute value

image_alt
Generate alt text from filename. Converts filename to human-readable alt text by: - Removing exten…
1 str
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

str

Alt text suggestion

image_data_uri
Convert image to data URI for inline embedding.
2 str
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

str

Data URI string