Quick Start

Overview

This page walks through the smallest working example: probing a file for its format and header properties, then seeing how the library handles a damaged file instead of raising an exception.


Probe a file

probe() is the main entry point. It reads just enough of the file header to populate an ImageInfo result — it never decodes pixel data:

from aspose_imaging_foss import probe

info = probe("photo.jpg")
print(f"{info.format}: {info.width}x{info.height}, {info.bit_depth}-bit")

ImageInfo exposes format, width, height, bit_depth, and frame_count — populated only when the detected format actually carries that data.


Probe a buffer or stream

probe() accepts a file path, a bytes buffer, or a binary stream directly, and detect_format() returns just the ImageFormat when you don’t need the full header:

from aspose_imaging_foss import detect_format, probe

with open("photo.jpg", "rb") as f:
    data = f.read()

format_only = detect_format(data)

with open("photo.jpg", "rb") as stream:
    info = probe(stream)

Handling truncated or malformed input

probe() never raises on malformed or truncated input. Instead of raising an exception, it returns a partial ImageInfo with whatever fields it managed to read — format is always set when the header’s format marker was recognized, even if the rest of the file is cut short:

from aspose_imaging_foss import probe

truncated = full_gif_bytes[:-2]  # last two bytes missing

info = probe(truncated)
print(info.format)  # GIF -- detected from the header alone

This makes probe() safe to run against untrusted or partially-downloaded files without wrapping every call in a try/except block.


Next Steps

See Also