image#

mediautils.image.get_all_jpeg_files(root_dir: str | PathLike, exclude: list[str] | None = None) list[Path][source]#

List all JPEG files under root_dir recursively.

Parameters:
  • root_dir (str | os.PathLike) – Root directory to search.

  • exclude (list[str] | None) – Substrings to exclude: any directory whose path contains one of these strings is skipped. If None, DEFAULT_EXCLUDE_PATTERNS is used. Pass an empty list to disable exclusions.

Return type:

list[Path]

mediautils.image.get_orientation(path: str | PathLike) str[source]#

Detect whether an image is portrait or landscape.

Takes EXIF orientation into account (rotation 90° or 270°). Square images are reported as "landscape".

Parameters:

path (str | os.PathLike) – Path to a JPEG image.

Returns:

"portrait" or "landscape".

Return type:

str

mediautils.image.process_images(src_dir: str | PathLike, dest_portrait: str | PathLike, dest_landscape: str | PathLike, max_dim: int = 1024, exclude: list[str] | None = None) list[Path][source]#

Dispatch JPEG images by orientation and resize them.

Collects all JPEG files under src_dir (recursively), detects each image’s orientation, copies it to dest_portrait or dest_landscape, and resizes it if its largest dimension exceeds max_dim.

Parameters:
  • src_dir (str | os.PathLike) – Source directory to scan for JPEG files.

  • dest_portrait (str | os.PathLike) – Output directory for portrait images.

  • dest_landscape (str | os.PathLike) – Output directory for landscape images.

  • max_dim (int) – Maximum size in pixels for the largest dimension.

  • exclude (list[str] | None) – Exclusion patterns passed to get_all_jpeg_files().

Returns:

Paths to the output files.

Return type:

list[Path]

mediautils.image.resize_image(path: str | PathLike, max_dim: int = 1024, out_dir: str | PathLike = 'out', out_name: str | None = None) Path[source]#

Write a copy of an image, resized if its largest dimension exceeds max_dim.

Images with EXIF orientation 6 or 8 (rotated 90°/270°) are copied without resizing to avoid corrupting the orientation metadata.

Parameters:
  • path (str | os.PathLike) – Path to the source image.

  • max_dim (int) – Maximum size in pixels for the largest dimension.

  • out_dir (str | os.PathLike) – Directory where the output file is saved. Created if it does not exist.

  • out_name (str | None) – Output file name. If None, the original file name is kept.

Returns:

Path to the output file.

Return type:

Path

mediautils.image.set_time_image(path: str | PathLike, dt: datetime, out_dir: str | PathLike = 'out', out_name: str | None = None) Path[source]#

Write a copy of an image with datetime_original set to dt.

Parameters:
  • path (str | os.PathLike) – Path to the source image.

  • dt (datetime) – The datetime to write into the EXIF metadata.

  • out_dir (str | os.PathLike) – Directory where the modified copy is saved. Created if it does not exist.

  • out_name (str | None) – Output file name. If None, the original file name is kept.

Returns:

Path to the output file.

Return type:

Path