image-polaroidImage Format Conversion

The ImageConvert class provides static and class methods for converting images, batch processing folders, and extracting detailed metadata from images.

❗Make sure you import the library as the following

from imageconvert import ImageConvert

The ImageConvert class provides static methods for converting images, batch processing directories, and retrieving image metadata.


📥 convert()

ImageConvert.convert(input_path, output_path, quality=95, dpi=None, preserve_metadata=True, preserve_timestamps=True)

Description

Convert a single image to another format while preserving metadata and file timestamps.

Parameters

Name
Type
Description

input_path

str

Path

output_path

str

Path

quality (optional)

int

Quality for lossy formats (1–100). Default: 95

dpi (optional)

tuple

None

preserve_metadata (optional)

bool

Preserve EXIF and metadata. Default: True

preserve_timestamps (optional)

bool

Preserve file creation/modification timestamps. Default: True

Returns

str: Path to the converted image.

Raises

  • FileNotFoundError

  • ValueError

  • RuntimeError

  • NotImplementedError

Example


📂 batch_convert()

Description

Batch convert all images in a folder to a specified format.

Parameters

Name
Type
Description

input_dir

str

Path

output_dir

str

Path

output_format (optional)

str

None

recursive (optional)

bool

Search subdirectories. Default: False

quality (optional)

int

Quality for lossy formats. Default: 95

preserve_metadata (optional)

bool

Preserve EXIF/metadata. Default: True

preserve_timestamps (optional)

bool

Preserve timestamps. Default: True

skip_existing (optional)

bool

Skip files if already converted. Default: True

Returns

List[str]: Paths to all successfully converted files.

Example


🔍 get_image_info()

Description

Get detailed metadata and properties of an image.

Parameters

Name
Type
Description

image_path

str

Path

Returns

Dict[str, Any] with keys like:

  • filename, path

  • width, height, format, mode

  • timestamps: created, modified, accessed

  • camera: {make, model, exposure_time, f_number, iso}

  • gps: {latitude, longitude, altitude}

  • exif_raw, raw_metadata

Example


is_supported_format()

Description

Check whether the given filename extension is supported.

Parameters

Name
Type
Description

filename

str

Name or path to file

Returns

bool: True if the format is supported, otherwise False.


🧩 get_extension()

Description

Extract the file extension from a filename or path.

Parameters

Name
Type
Description

filename

str

File path or filename

Returns

str: File extension including the dot, in lowercase (e.g., .jpg)

Last updated