Transform

class imgproxykit.Transform(*options: Option, **kwargs: Unpack[ScalarOptions])[source]

Define reusable image processing options.

Stores an immutable tuple of options for reuse with imgproxykit.Client.url(). Pass option instances or scalar keyword arguments; scalar options follow the positional options in keyword order. Use extend() to create a new transformation with additional options without changing the original.

Options retain their supplied order during serialization. Imgproxy determines the image processing pipeline and resolves omitted arguments using its defaults. Preset options reference names configured on the imgproxy server and are not expanded here.

options

Tuple of processing options. Defaults to an empty tuple, which adds no processing option segments to the URL.

Type:

tuple[Option, ...]

Collect positional options, followed by scalar keyword options.

Parameters:
*options: Option

Processing option instances in serialization order. Repeated options are retained without merging.

**kwargs: Unpack[ScalarOptions]

Scalar processing arguments, such as quality=85 or format='webp'. Converted to option instances and appended in keyword order.

Examples

Combine a resize option with scalar quality and format options:

>>> from imgproxykit import Transform
>>> from imgproxykit.options import Resize
>>> thumbnail = Transform(
...     Resize.fill(width=96, height=96),
...     quality=85,
...     format='webp',
... )
>>> [option.name for option in thumbnail.options]
['resize', 'quality', 'format']
extend(*options: Option, **kwargs: Unpack[ScalarOptions]) → Transform[source]

Return a new transformation with additional processing options.

The original transformation remains unchanged. Existing options are followed by positional options, then scalar keyword options in keyword order. Repeated options are retained without merging or replacing them.

Parameters:
*options: Option

Additional processing option instances.

**kwargs: Unpack[ScalarOptions]

Additional scalar processing arguments.

Return type:

Transform

Examples

>>> base = Transform(quality=85, format='webp')
>>> retina = base.extend(dpr=2)
>>> [option.name for option in base.options]
['quality', 'format']
>>> [option.name for option in retina.options]
['quality', 'format', 'dpr']

Scalar keyword arguments

class imgproxykit.transform.ScalarOptions[source]

Optional scalar processing arguments.

Accepted by Transform and extend().

Extra items:

Never