---
Product: imaging
Platform: python
Page Type: index
Canonical URL: https://products.aspose.org/imaging/python/
---

# Aspose.Imaging FOSS for Python

Zero-dependency Python library for detecting image formats and reading header metadata — dimensions, bit depth, frame count — directly from the file header, without decoding pixels. MIT licensed.

MIT-licensed, zero-dependency Python library for detecting 14 image formats and reading header metadata without decoding pixels.

## Aspose.Imaging FOSS — Open Source Python Image Format Detection Library

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](https://products.aspose.com/imaging/python/).

## Format Detection API

- **File, buffer, or stream input:** `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.
- **Format-only detection:** `detect_format()` reads up to the first 132 bytes and returns just the `ImageFormat` enum value, without reading further into the header.
- **Full metadata:** `probe()` returns an `ImageInfo` with `format` plus nullable `width`, `height`, `bit_depth`, and `frame_count` — populated only when the format actually carries that data.
- **Asyncio support:** `probe_async()` mirrors `probe()` for asyncio applications, accepts async-read streams, and supports task cancellation.

## When You Need Fast Format Detection

- **Upload validation:** Confirm an uploaded file really is an image, and of a recognized format, before passing it to a heavier pipeline.
- **Thumbnail sizing:** Read `width`/`height` from a file header to lay out a UI without loading the full image.
- **Batch triage:** Sort a directory of mixed image files by detected format without decoding any of them.
- **Async web services:** Probe uploaded images inside an asyncio request handler without blocking the event loop.

## Broad, Resilient Format Coverage

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.

- **14 formats, including ones with no other FOSS Python detector:** PSD, EMF/WMF, DICOM, DjVu, AVIF, and HEIC are covered alongside the common raster formats.
- **DICOM transfer syntax coverage:** Implicit VR Little Endian and Explicit VR Little/Big Endian, including metadata preceding JPEG-compressed pixel data.
- **Never raises on truncated input:** `probe()` and `probe_async()` keep the format and metadata already read when a header is cut short, rather than raising an exception.

## Where Resilience Matters

- **Untrusted uploads:** Probe user-submitted files without a single truncated header crashing the request.
- **Partial downloads:** Detect the format of a truncated or in-progress file transfer.
- **Legacy file archives:** Identify old PSD, EMF, WMF, or DjVu files mixed into a general-purpose archive.
- **Multi-frame media:** Read `frame_count` for animated PNG/APNG, GIF, WebP, ICO, and TIFF, and branch downstream logic on the result.

## Detect a Format and Read Header Metadata from a File

Install the package, then probe a file from disk.

```bash
git clone https://github.com/aspose-imaging-foss/Aspose.Imaging-FOSS-for-Python.git
cd Aspose.Imaging-FOSS-for-Python
pip install -e .
```

```python
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 Asynchronously

`probe_async()` mirrors `probe()` for asyncio applications and accepts the same path, buffer, or stream inputs.

```python
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())
```

## Field Support by Format

| 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) | — | — |

## Support and Learning Resources

- [Documentation](https://docs.aspose.org/imaging/python/)
- [API References](https://reference.aspose.org/imaging/python/)
- [Free Support](https://forum.aspose.org/)
- [Contribution](https://contribution.aspose.org/)
- [Blog](https://blog.aspose.org/)
- [New Releases](https://releases.aspose.org/)