PHPackages                             rosell-dk/image-mime-type-sniffer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. rosell-dk/image-mime-type-sniffer

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

rosell-dk/image-mime-type-sniffer
=================================

Sniff mime type (images only)

1.1.1(4y ago)27.0M—5.5%1MITPHPPHP &gt;=5.4

Since Apr 7Pushed 2y ago1 watchersCompare

[ Source](https://github.com/rosell-dk/image-mime-type-sniffer)[ Packagist](https://packagist.org/packages/rosell-dk/image-mime-type-sniffer)[ GitHub Sponsors](https://github.com/rosell-dk)[ Fund](https://ko-fi.com/rosell)[ RSS](/packages/rosell-dk-image-mime-type-sniffer/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (5)Versions (5)Used By (1)

Image Mime Type Sniffer
=======================

[](#image-mime-type-sniffer)

[![Latest Stable Version](https://camo.githubusercontent.com/f8c2d7233e24ac734e5a1433b93926b0e20e7486acdc778cd9057514bca696c7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f726f73656c6c2d646b2f696d6167652d6d696d652d747970652d736e69666665722e737667)](https://packagist.org/packages/rosell-dk/image-mime-type-sniffer)[![Minimum PHP Version](https://camo.githubusercontent.com/2b1a0215eae27de3825527ae33112cf11ae5cf50be0e448efdb4b2a43ccee554/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f726f73656c6c2d646b2f696d6167652d6d696d652d747970652d736e6966666572)](https://php.net)[![Build Status](https://camo.githubusercontent.com/4cc376f31b722375d65d13a0844d1119aaa150b83b14ae80ceecf5a9ba288217/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f726f73656c6c2d646b2f696d6167652d6d696d652d747970652d736e69666665722f63692e796d6c3f6272616e63683d6d6173746572266c6f676f3d476974487562267374796c653d666c61742d737175617265266c6162656c3d6275696c64)](https://github.com/rosell-dk/image-mime-type-sniffer/actions/workflows/ci.yml)[![Software License](https://camo.githubusercontent.com/c034ea3669e2235bbe1c2c8756eecebcc6384b71bfec57ad155c5e3f33cd1387/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d3431383637372e737667)](https://github.com/rosell-dk/image-mime-type-sniffer/blob/master/LICENSE)[![Coverage](https://camo.githubusercontent.com/04912873cf0adbdeac758de74688d6fd44ebec14568af3ed8e71ffcca9c26d4b/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f75726c3d68747470733a2f2f6c6974746c652d622e69742f696d6167652d6d696d652d747970652d736e69666665722f636f64652d636f7665726167652f636f7665726167652d62616467652e6a736f6e)](http://little-b.it/image-mime-type-sniffer/code-coverage/coverage/index.html)[![Monthly Downloads](https://camo.githubusercontent.com/76e8547a32f6676fea88170b750e06f653ab6bb24b6d91a395d83f4856955ebe/687474703a2f2f706f7365722e707567782e6f72672f726f73656c6c2d646b2f696d6167652d6d696d652d747970652d736e69666665722f642f6d6f6e74686c79)](https://packagist.org/packages/rosell-dk/image-mime-type-sniffer)[![Dependents](https://camo.githubusercontent.com/cebeb2ec3069e814be1db2f8c3b39980f790350399e4d785f1ba6753e420c096/687474703a2f2f706f7365722e707567782e6f72672f726f73656c6c2d646b2f696d6167652d6d696d652d747970652d736e69666665722f646570656e64656e7473)](https://packagist.org/packages/rosell-dk/image-mime-type-sniffer/dependents?order_by=downloads)

Gets mime type of common *image* files by sniffing the file content, looking for signatures.

The fact that this library limits its ambition to sniff images makes it light and simple. It is also quite fast. Most other sniffers iterates through all common signatures, however this library uses a mix of finite-state machine approach and iteration to achieve a good balance of speed, compactness, simplicity and readability.

The library recognizes the most widespread image formats, such as GIF, JPEG, WEBP, AVIF, JPEG-2000 and HEIC.

Usage
=====

[](#usage)

```
use \ImageMimeTypeSniffer\ImageMimeTypeSniffer;

$mimeType = ImageMimeTypeSniffer::detect($fileName);
if (is_null($mimeType)) {
  // mimetype was not detected, which means the file is probably not an image (unless it is a rare type)
} else {
  // It is an image, and we know the mimeType
}
```

PS: An `\Exception` is thrown if the file is unreadable.

Platforms
=========

[](#platforms)

Works on (at least): OS: Ubuntu (22.04, 20.04), Windows (2022, 2019), Mac OS (11, 10.15) PHP: 5.6 - 8.2 (also tested 8.3 and 8.4 development versions in October 2023)

Each new release will be tested on all combinations of OSs and PHP versions that are [supported](https://github.com/marketplace/actions/setup-php-action) by GitHub-hosted runners. Except that we do not below PHP 5.6.

Testing consists of running the unit tests. The code in this library is almost completely covered by tests (~97% coverage).

Release 1.1.1 has been tested in PHP: 5.6 - 8.2 on the following OSs: Ubuntu (22.04, 20.04, 18.04), Windows (2022, 2019), Mac OS (13, 12, 11, 10.15). Code coverage: ~97%. For some reason PHP 5.6 testing fails on Windows

List of recognized image types:
===============================

[](#list-of-recognized-image-types)

- application/psd
- image/avif
- image/bmp
- image/gif
- image/heic
- image/jp2
- image/jp20
- image/jpeg
- image/jpm
- image/jpx
- image/png
- image/svg+xml
- image/tiff
- image/webp
- image/x-icon
- video/mj2

TODO: image/heif

Alternatives
============

[](#alternatives)

I have created a library that uses this library as well as other methods (*finfo*, *exif\_imagetype*, etc) for determining image type. You might want to use that instead, to cover all bases. It is available here: [image-mime-type-guesser](https://github.com/rosell-dk/image-mime-type-guesser).

There are also other PHP mime type sniffers out there:

-
-
-
-
-

Do you like what I do?
----------------------

[](#do-you-like-what-i-do)

Perhaps you want to support my work, so I can continue doing it :)

- [Become a backer or sponsor on Patreon](https://www.patreon.com/rosell).
- [Buy me a Coffee](https://ko-fi.com/rosell)

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity47

Moderate usage in the ecosystem

Community9

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~4 days

Total

4

Last Release

1489d ago

Major Versions

0.1 → 1.02022-04-08

PHP version history (2 changes)0.1PHP ^5.6 | ^7.0 | ^8.0

1.1PHP &gt;=5.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/17592708?v=4)[Bjørn Rosell](/maintainers/rosell-dk)[@rosell-dk](https://github.com/rosell-dk)

---

Top Contributors

[![rosell-dk](https://avatars.githubusercontent.com/u/17592708?v=4)](https://github.com/rosell-dk "rosell-dk (164 commits)")

---

Tags

imagemimemime-typeimages

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/rosell-dk-image-mime-type-sniffer/health.svg)

```
[![Health](https://phpackages.com/badges/rosell-dk-image-mime-type-sniffer/health.svg)](https://phpackages.com/packages/rosell-dk-image-mime-type-sniffer)
```

###  Alternatives

[symfony/mime

Allows manipulating MIME messages

2.8k668.8M911](/packages/symfony-mime)[rosell-dk/image-mime-type-guesser

Guess mime type of images

108.0M5](/packages/rosell-dk-image-mime-type-guesser)[zbateson/mail-mime-parser

MIME email message parser

53949.2M79](/packages/zbateson-mail-mime-parser)[php-mime-mail-parser/php-mime-mail-parser

A fully tested email parser for PHP 8.0+ (mailparse extension wrapper).

9979.6M27](/packages/php-mime-mail-parser-php-mime-mail-parser)[nette/mail

📧 Nette Mail: A handy library for creating and sending emails in PHP.

5389.8M246](/packages/nette-mail)[fileeye/mimemap

A PHP library to handle MIME Content-Type fields and their related file extensions.

259.2M9](/packages/fileeye-mimemap)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
