Detect image file types from Buffer/Uint8Array data with support for 20+ formats including PNG, JPEG, WebP, and HEIC.
image-type is a JavaScript library that detects image file formats by analyzing binary data from Buffer, ArrayBuffer, or Uint8Array inputs. It identifies 20+ image types including PNG, JPEG, WebP, and HEIC by examining the first bytes of data, solving the problem of determining image formats without relying on file extensions or metadata.
JavaScript developers working with image processing in Node.js or browser environments, particularly those building applications that handle image uploads, processing pipelines, or media management systems.
Developers choose image-type for its lightweight, efficient detection that works with partial binary data, its support for modern formats like HEIC and WebP, and its seamless integration with both Node.js and browser JavaScript environments without external dependencies.
Detect the image type of a Buffer/Uint8Array
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Supports over 20 image formats, including modern ones like HEIC and WebP, as listed in the README, ensuring comprehensive detection for diverse image types.
Only requires the first 4100 bytes (via minimumBytes) for detection, minimizing memory usage and speeding up processing without reading entire files, as per the API description.
Works seamlessly in both Node.js and browser environments, with usage examples provided for each, enabling consistent image checking across different JavaScript runtimes.
Returns a promise that resolves to an object with extension and MIME type, aligning with contemporary asynchronous JavaScript patterns for better integration in async workflows.
Explicitly does not support SVG files, as noted in the README, because SVG requires full file reading, limiting its utility for projects dealing with vector graphics.
Requires input as ArrayBuffer or Uint8Array, which can be cumbersome for developers working with other data types like streams or files without direct binary access.
Limited to image formats only; for broader file detection, users must rely on the separate file-type module, adding complexity if mixed file types are involved.
The minimumBytes value (4100) can change, and hardcoding it is discouraged, potentially leading to breaking changes or maintenance issues in long-term projects.