sirv/sirv-image
Composer 安装命令:
composer require sirv/sirv-image
包简介
Official PHP SDK for the Sirv dynamic imaging API. This SDK provides a simple way to request any modified image (dimensions, format, quality, sharpen, crop, watermark etc.) using the 100+ image transformation options in Sirv's image optimization service.
关键字:
README 文档
README
A fluent URL builder for Sirv dynamic image transformations. Build transformed image URLs with an intuitive, chainable API — no API credentials required.
Installation
composer require sirv/sirv-image
Quick Start
use Sirv\SirvImage; $url = (new SirvImage('https://demo.sirv.com/image.jpg')) ->resize(300, 200) ->format('webp') ->quality(80) ->toUrl(); // https://demo.sirv.com/image.jpg?w=300&h=200&format=webp&q=80
Constructor
// Full image URL new SirvImage('https://demo.sirv.com/image.jpg'); // Base URL + path new SirvImage('https://demo.sirv.com', '/image.jpg');
API Reference
All methods return $this for chaining. Call ->toUrl() to get the final URL. Casting to string also works.
Resize
| Method | Parameters | Description |
|---|---|---|
resize($width, $height, $option) |
int|null, int|null, string|null |
Resize with optional scale option |
width($w) |
int |
Set width |
height($h) |
int |
Set height |
scaleByLongest($s) |
int |
Resize by longest dimension |
thumbnail($size = 256) |
int |
Create square thumbnail |
Crop
| Method | Parameters | Description |
|---|---|---|
crop($w, $h, $x, $y, $type, $padW, $padH) |
all nullable | Crop image |
clipPath($name) |
string |
Apply clipping path |
Rotation
| Method | Description |
|---|---|
rotate($degrees) |
Rotate (-180 to 180) |
flip() |
Flip vertically |
flop() |
Flip horizontally |
Format & Quality
| Method | Parameters | Description |
|---|---|---|
format($fmt) |
string |
Output format |
quality($q) |
int |
JPEG quality (0-100) |
webpFallback($fmt) |
string |
WebP fallback |
subsampling($value) |
string |
Chroma subsampling |
pngOptimize($enabled = true) |
bool |
PNG optimization |
gifLossy($level) |
int |
GIF lossy compression |
Color Adjustments
brightness($v), contrast($v), exposure($v), hue($v), saturation($v), lightness($v), shadows($v), highlights($v) — all accept int (-100 to 100).
grayscale(), colorLevel($black, $white), histogram($channel)
Color Effects
| Method | Parameters | Description |
|---|---|---|
colorize($color, $opacity) |
string, int |
Color overlay |
colortone($preset) |
string |
Preset colortone |
colortone(null, $options) |
array |
Custom colortone with color, level, mode |
Effects
blur($v), sharpen($v), vignette($value, $color), opacity($v)
Text Overlay
->text('Hello', [ 'fontSize' => 32, 'fontFamily' => 'Arial', 'fontStyle' => 'italic', 'fontWeight' => 700, 'color' => 'white', 'opacity' => 80, 'outlineWidth' => 2, 'outlineColor' => 'black', 'backgroundColor' => 'red', 'backgroundOpacity' => 50, 'align' => 'center', 'position' => 'center', 'positionX' => 10, 'positionY' => 20, 'positionGravity' => 'northwest', ])
Watermark
->watermark('/logo.png', [ 'position' => 'southeast', 'opacity' => 50, 'scaleWidth' => '20%', 'scaleOption' => 'fit', 'rotate' => 45, 'layer' => 'front', ])
Canvas & Frame
->canvas(['width' => 800, 'height' => 600, 'color' => 'ffffff', 'aspectRatio' => '16:9', 'borderWidth' => 10]) ->frame(['style' => 'solid', 'color' => '333', 'width' => 5, 'rimColor' => 'gold', 'rimWidth' => 2])
Other
| Method | Description |
|---|---|
page($num) |
PDF page |
profile($name) |
Saved profile |
Examples
E-commerce Product
$url = (new SirvImage('https://demo.sirv.com/products/shoe.jpg')) ->resize(800, 600, 'fill') ->format('webp') ->quality(85) ->watermark('/brand-logo.png', ['position' => 'southeast', 'opacity' => 30]) ->toUrl();
Vintage Effect
$url = (new SirvImage('https://demo.sirv.com/photo.jpg')) ->colortone('sepia') ->vignette(40) ->frame(['style' => 'solid', 'color' => 'f5e6d3', 'width' => 20]) ->toUrl();
Testing
./vendor/bin/phpunit tests/
License
MIT
sirv/sirv-image 适用场景与选型建议
sirv/sirv-image 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「image」 「cdn」 「responsive」 「gallery」 「zoom」 「image-processing」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sirv/sirv-image 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sirv/sirv-image 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sirv/sirv-image 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
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.
ResponsiveImages Plugin for October CMS
TYPO3 extension for sending responsive email templates
The Yii2 extension uses jQuery PrettyPhoto and OwlCarousel js and makes image galary from php array of structure defined.
Automatically rewrites the URLs of media and assets to use a CDN
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 44
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-25