php-collective/file-storage-image-processor
Composer 安装命令:
composer require php-collective/file-storage-image-processor
包简介
File Storage Image Processor
README 文档
README
Image Processing for the File Storage Library.
Built on top of Intervention Image v4.
Features
- Generates and stores variants of an uploaded image (thumbnails, avatars, hero crops, …)
- 24+ first-class image operations: resize, scale, cover, crop, rotate, flip, sharpen, orient (EXIF auto-rotate), brightness, contrast, grayscale, colorize, blur, pixelate, trim, resizeCanvas, padding, place (watermark), convert (format swap), …
- Per-format encoder quality, EXIF/metadata strip toggle, ICC color-profile preservation
- Pluggable operation registry — add custom operations without forking
- Optional file-size optimization via spatie/image-optimizer
- Works with League Flysystem for flexible storage backends
- Fluent API for chaining operations, including repeating the same operation type multiple times
Requirements
- GD or Imagick extension
- Intervention Image v4
Installation
composer require php-collective/file-storage-image-processor
Quick Example
use PhpCollective\Infrastructure\Storage\Processor\Image\Driver; use PhpCollective\Infrastructure\Storage\Processor\Image\Format; use PhpCollective\Infrastructure\Storage\Processor\Image\ImageProcessor; use PhpCollective\Infrastructure\Storage\Processor\Image\ImageVariantCollection; use PhpCollective\Infrastructure\Storage\Processor\Image\Position; // Driver::Auto picks Imagick when the extension is loaded and falls // back to GD; use Driver::Gd or Driver::Imagick to choose explicitly. $imageProcessor = ImageProcessor::create(Driver::Auto, $fileStorage, $pathBuilder); $collection = ImageVariantCollection::create(); // Create a thumbnail with aspect ratio preserved $collection->addNew('thumbnail') ->scale(300, 300) ->optimize(); // Create an avatar that fills exact dimensions $collection->addNew('avatar') ->cover(150, 150, Position::TopCenter) ->optimize(); // Re-encode a JPEG source as WebP — Format enum or string both work $collection->addNew('webp') ->scale(800, 600) ->convert(Format::Webp); // Repeat the same operation type without losing earlier steps $collection->addNew('effects') ->blur(1) ->blur(6); $file = $file->withVariants($collection->toArray()); $file = $imageProcessor->process($file);
Tuning the encoder
$imageProcessor ->setQuality(['webp' => 80, 'jpg' => 90, 'avif' => 70]) // per-format ->setStripExif(true) // privacy + smaller files (default) ->setPreserveProfile(true) // keep wide-gamut color rendering (default) ->setPreserveAnimation(true); // animated GIF/WebP keep all frames (default)
setPreserveAnimation(false) flattens animated sources to a single frame — useful for static thumbnail variants or when converting to a non-animated format like JPEG.
Processing a subset of variants
// Per-call filter — does not leak into subsequent process() calls. $file = $imageProcessor->process($file, ['thumbnail']);
Custom operations
use PhpCollective\Infrastructure\Storage\Processor\Image\Operation\Operation; use PhpCollective\Infrastructure\Storage\Processor\Image\Operation\OperationRegistry; $registry = OperationRegistry::default() ->register('myFilter', static fn (array $args): Operation => new MyFilter(...$args)); $processor = new ImageProcessor($storage, $pathBuilder, $imageManager, urlBuilder: null, operationRegistry: $registry);
Repeated operations of the same name are preserved in order when you serialize variants with toArray() and rebuild them later with ImageVariantCollection::fromArray().
Documentation
Please start by reading the documentation in the docs/ directory:
- Installation & Setup
- Processing Images
- Available Operations — complete reference of all image operations
Upgrading from 1.x to 2.x
This major release migrates to Intervention Image v4 and replaces the stringly-typed dispatcher with a typed Operation class hierarchy. See the CHANGELOG for the full list; the headline changes:
- PHP 8.3+ required (was 8.1)
- Intervention Image v4 required (was v3)
processOnlyTheseVariants()/processAll()removed — use the newprocess($file, ['thumbnail'])per-call filter insteadOperations::POSITION_*string constants replaced by thePositionenum (Position::Center,Position::TopCenter, …)ImageVariant::FLIP_HORIZONTAL/FLIP_VERTICALconstants replaced by theFlipDirectionenumOperationsclass is gone — operations are now individual classes undersrc/Operation/resolved viaOperationRegistryflip()now acceptsFlipDirection|string(string form still works for config-driven setups)cover()no longer takes a (always-ignored)$callbackparameter
php-collective/file-storage-image-processor 适用场景与选型建议
php-collective/file-storage-image-processor 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11.52k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 11 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「image processing」 「persistence」 「media」 「storage」 「files」 「file system」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 php-collective/file-storage-image-processor 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 php-collective/file-storage-image-processor 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 php-collective/file-storage-image-processor 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This bundle provides tools to build persistence-agnostic storage layer.
Propel2 is an open-source Object-Relational Mapping (ORM) for PHP 5.5 and up.
Kinikit - PHP Application development framework MVC component
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.
paywant api php client
统计信息
- 总下载量: 11.52k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 3
- 推荐数: 2
其他信息
- 授权协议: MIT
- 更新时间: 2023-11-14