Aspose.Imaging FOSS for Python identifies an image file’s format and reads its basic header properties — dimensions, bit depth, and frame count — directly from the file header, without decoding a single pixel. detect_format() reads an image’s signature and returns an ImageFormat enum value; probe() reads further into the header when needed and returns an ImageInfo object with nullable width, height, bit_depth, and frame_count properties, populated only when the detected format actually carries that value. Both functions accept a file path, a byte buffer, or a binary stream, including non-seekable streams.
The library detects 14 formats — PNG/APNG, JPEG, BMP, PSD, GIF, WebP, ICO, TIFF, EMF, WMF, DICOM, DjVu, AVIF, and HEIC — with DICOM transfer-syntax coverage for Implicit VR Little Endian and Explicit VR Little/Big Endian. An await probe_async(source) entry point mirrors probe() for asyncio applications, accepting async-read streams such as asyncio.StreamReader and supporting task cancellation. If a header is truncated, probe() and probe_async() keep the format they already detected and any metadata already read, rather than raising.
Aspose.Imaging FOSS for Python is MIT-licensed, runs on Python 3.10 or later, and depends on nothing beyond the standard library. It is intentionally scoped to format detection only — for decoding, editing, or converting these image formats, see Aspose.Imaging for Python — Enterprise Product.
detect_format() and probe() accept a file path, a byte buffer, or a binary stream — seekable streams are read from the start, non-seekable streams from the current position.detect_format() reads up to the first 132 bytes and returns just the ImageFormat enum value, without reading further into the header.probe() returns an ImageInfo with format plus nullable width, height, bit_depth, and frame_count — populated only when the format actually carries that data.probe_async() mirrors probe() for asyncio applications, accepts async-read streams, and supports task cancellation.width/height from a file header to lay out a UI without loading the full image.Field population varies by format — every format is detected, but only some carry bit depth or frame count in their header. See the field support table below for the exact breakdown.
probe() and probe_async() keep the format and metadata already read when a header is cut short, rather than raising an exception.frame_count for animated PNG/APNG, GIF, WebP, ICO, and TIFF, and branch downstream logic on the result.Install the package, then probe a file from disk.
git clone https://github.com/aspose-imaging-foss/Aspose.Imaging-FOSS-for-Python.git
cd Aspose.Imaging-FOSS-for-Python
pip install -e .from aspose_imaging_foss import ImageFormat, detect_format, probe
assert detect_format(b"GIF89a") == ImageFormat.GIF
info = probe("drawing.emf")
print(info.width, info.height, info.frame_count)
probe_async() mirrors probe() for asyncio applications and accepts the same path, buffer, or stream inputs.
import asyncio
from aspose_imaging_foss import probe_async
async def main():
info = await probe_async("drawing.emf")
print(info.width, info.height)
asyncio.run(main())
| Format | Width / Height | Bit depth | Frame count |
|---|---|---|---|
| PNG / APNG | ✓ | ✓ | ✓ (APNG) |
| JPEG | ✓ | ✓ | — |
| BMP | ✓ | ✓ | — |
| PSD | ✓ | ✓ | — |
| GIF | ✓ | — | ✓ |
| WebP | ✓ | — | ✓ |
| ICO | ✓ (first image) | ✓ (first image) | ✓ (image count) |
| TIFF | ✓ (first page) | ✓ (per channel) | ✓ (page count) |
| EMF | ✓ (from bounds) | — | — |
| WMF (placeable) | ✓ (assumes 96 DPI) | — | — |
| DICOM | ✓ (Rows/Columns) | ✓ (BitsAllocated) | — |
| DjVu | ✓ (page dimensions) | — | ✓ (embedded pages) |
| AVIF / HEIC | ✓ (primary image) | — | — |