rosell-dk/image-mime-type-sniffer
Composer 安装命令:
composer require rosell-dk/image-mime-type-sniffer
包简介
Sniff mime type (images only)
关键字:
README 文档
README
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
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
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 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:
- 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
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.
There are also other PHP mime type sniffers out there:
- https://github.com/Intervention/mimesniffer
- https://github.com/Tinram/File-Identifier
- https://github.com/shanept/MimeSniffer
- https://github.com/zjsxwc/mime-type-sniffer
- https://github.com/thephpleague/mime-type-detection/tree/main/src
Do you like what I do?
Perhaps you want to support my work, so I can continue doing it :)
rosell-dk/image-mime-type-sniffer 适用场景与选型建议
rosell-dk/image-mime-type-sniffer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.91M 次下载、GitHub Stars 达 2, 最近一次更新时间为 2022 年 04 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「image」 「mime」 「images」 「mime type」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 rosell-dk/image-mime-type-sniffer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 rosell-dk/image-mime-type-sniffer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 rosell-dk/image-mime-type-sniffer 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PHP class providing static methods for reading, writing, copying, moving, and deleting files and directories, MIME type detection, image size detection, and file permission management
Parse a generic mail stream, and convert it to a SwiftMailer Message
A Laravel Nova field for distribute your images as array of object.
Pexels API Client for www.pexels.com
Yii2 LightBox image galary widget uses Lightbox v2.10.0 by Lokesh Dhakar
The Yii2 extension uses jQuery jquery.carousel-1.1.min.js and makes image carousel from php array of structure defined.
统计信息
- 总下载量: 7.91M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 32
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-04-07