imgCompressor

Compress selected supported images to JPG while reducing JPEG quality toward the requested approximate target size.

Function

imgCompressor(targetSizeMB=1, source=None)

Parameters

targetSizeMB

Type: int or float, default 1

Approximate target size per output image in megabytes. Must be greater than zero.

source

Type: path, iterable of paths, or None

Optional image input. If omitted, all supported images in the current folder are discovered.

Returns

A list of `Path` objects for compressed JPG files, or `None` when no images are found.

Examples

Compress all images

imgCompressor()

Target about 2 MB per image

imgCompressor(2)

Compress watermarked images

imgCompressor(source=imgWatermark("PREETAM"))

Notes

The target is approximate. The function lowers JPEG quality in steps and stops at the first result at or below the target, or at quality 15 if the target cannot be reached before the lower bound.

Dynamic input behavior

When source is omitted, Toolvix discovers matching files in the current working folder. When source is supplied, only the supplied files are processed. This makes nested pipelines deterministic.

Back to function index · Nesting and chaining