smallpics/craft-smallpics
Composer 安装命令:
composer require smallpics/craft-smallpics
包简介
Small Pics image transformer for Craft
README 文档
README
Add Small Pics transforms to image URLs in Craft CMS.
Requirements
- Craft CMS 4.5+ or 5.0+
- PHP 8.1+
Installation
composer require smallpics/craft-smallpics ./craft plugin/install smallpics
Configuration
Create config/smallpics.php.
Single Origin
return [ 'transformNativeImages' => true, 'nativeTransformsParams' => [ 'q' => 55, ], 'transformThumbnails' => true, 'thumbnailParams' => [ 'q' => 50, ], 'baseUrl' => getenv('SMALLPICS_BASE_URL'), 'secret' => getenv('SMALLPICS_SECRET') ?: null, 'transformSvgs' => false, 'transformAnimatedGifs' => false, 'defaultParams' => [ 'fm' => 'avif', // Don't set a default format if you've enabled `transformAnimatedGifs` 'q' => 65, ], ];
Multiple Origins
Use origin labels to select the source setup for an image. The label is only used by the plugin and is not added to generated URLs.
return [ 'transformNativeImages' => true, 'nativeTransformsParams' => [ 'q' => 55, ], 'transformThumbnails' => true, 'thumbnailParams' => [ 'q' => 50, ], 'defaultOrigin' => 'productImages', 'origins' => [ 'productImages' => [ 'baseUrl' => getenv('SMALLPICS_PRODUCTS_BASE_URL'), 'secret' => getenv('SMALLPICS_PRODUCTS_SECRET') ?: null, 'transformSvgs' => false, 'transformAnimatedGifs' => false, 'defaultParams' => [ 'q' => 80, ], ], 'editorialImages' => [ 'baseUrl' => getenv('SMALLPICS_EDITORIAL_BASE_URL'), 'secret' => getenv('SMALLPICS_EDITORIAL_SECRET') ?: null, 'transformSvgs' => false, 'transformAnimatedGifs' => false, ], ], ];
Native Craft Transforms
Native Craft image transforms are handled automatically when transformNativeImages is enabled. Use nativeTransformsParams to set Small Pics params for native transforms only.
{{ asset.getUrl({ width: 800, height: 600, mode: 'crop' }) }}
{{ asset.getImg('hero') }}
{{ asset.getSrcset(['400w', '800w'], { width: 800 }) }}
Craft thumbnail URLs are handled automatically when transformThumbnails is enabled. Use thumbnailParams to override defaults for thumbnails.
return [ 'transformThumbnails' => true, 'thumbnailParams' => [ 'q' => 50, ], ];
Twig
transformImage() returns a TransformedImage. Rendering it as a string outputs the URL.
<img src="{{ craft.smallpics.transformImage(asset, { w: 800, h: 600, fit: 'cover', fm: 'webp', q: 80 }) }}">
You can also pass a named Craft transform handle as the config.
<img src="{{ craft.smallpics.transformImage(asset, 'hero') }}">
Select an origin with origin.
{{ craft.smallpics.transformImage(asset, {
origin: 'editorialImages',
w: 1200,
fm: 'avif'
}) }}
srcset() takes the image, descriptors, and common config.
<img srcset="{{ craft.smallpics.srcset( asset, { '1x': { dpr: 1 }, '2x': { dpr: 2 }, '800w': { w: 800 } }, { w: 400, h: 300, fit: 'cover', fm: 'webp' } ) }}">
Transform Options
See the Small Pics docs for the full list of supported transform parameters.
Craft transform keys are translated to Small Pics keys when native transforms are intercepted:
| Craft key | Small Pics param |
|---|---|
width |
w |
height |
h |
quality |
q |
mode |
fit |
position |
cover position in fit |
fill |
bg |
PHP
use smallpics\craft\Plugin; $image = Plugin::getInstance()->getTransformer()->transformImage( $asset, [ 'w' => 800, 'h' => 600, 'fm' => 'webp', ] ); $url = (string) $image;
$srcset = Plugin::getInstance()->getTransformer()->srcset( $asset, [ '1x' => ['dpr' => 1], '2x' => ['dpr' => 2], ], [ 'w' => 400, 'h' => 300, 'fit' => 'cover', ] ); $srcsetValue = (string) $srcset;
smallpics/craft-smallpics 适用场景与选型建议
smallpics/craft-smallpics 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 07 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「images」 「transformer」 「processing」 「craftcms」 「smallpics」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 smallpics/craft-smallpics 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 smallpics/craft-smallpics 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 smallpics/craft-smallpics 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Serializer transformers outputting valid API responses in JSON, JSON API and HAL+JSON API formats.
Symfony 2 & 3 JSON API Transformer Package
A Laravel Nova field for distribute your images as array of object.
Pexels API Client for www.pexels.com
A simple library that allows transform any kind of data to native php data or whatever
HAL+JSON & HAL+XML API transformer outputting valid API responses.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-07-15