tomlutzenberger/yii2-responsive-image
Composer 安装命令:
composer require tomlutzenberger/yii2-responsive-image
包简介
Create thumbnails with custom presets and use them in responsive widgets
README 文档
README
Yii2 Responsive Image
Create thumbnails with custom presets and use them in responsive widgets
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist tomlutzenberger/yii2-responsive-image "*"
or add
"tomlutzenberger/yii2-responsive-image": "*"
to the required section of your composer.json file.
Usage
Once the extension is installed, add the component to your web.php:
// ... 'components' => [ // ... 'responsiveImage' => [ 'class' => 'TomLutzenberger\ResponsiveImage\components\ResponsiveImage', 'presets' => [ // Your presets here ], ], ],
Defining a preset
A preset is like a template for both the thumbnail generator and the picture widget.
'preset-name' => [ // Path where the source images are stored // Must be absolute and web-accessible -> @webroot // Will be used to bulk-generate via console command // Required 'srcPath' => '@webroot/img/some_path', // Path where the thumbnails should be stored // Must be absolute and web-accessible -> @webroot // If not set, component's defaultTargetPath will be used // Optional 'targetPath' => '@webroot/img/some_path/preset-name', // File extension of the thumbnails // If not set, thumbnail will have the same extension as source file // Optional 'targetExtension' => 'jpg', // Thumbnail width and height in pixels // At least one of them is required 'width' => 480, 'height' => 400, // Image quality in percent // Optional 'quality' => 80, // Viewport breakpoints for the Picture widget // Thumbnails gets only displayed within this breakpoint (min and/or max) // At least one of them is required 'breakpointMin' => 992, 'breakpointMax' => 1200, // Enable/disable cache-busting for a single preset // Optional, defaults to `true` 'cacheBusting' => true, ],
Using the picture widget
Just set the source image and the presets you want to use.
Important:
- Path of the source image must be an alias and web-accessible, so either
@webor@webroot - Path of the source image need to match
srcPathof the preset
<?= TomLutzenberger\ResponsiveImage\widgets\Picture::widget([ 'image' => '@web/image/content/my-image.jpg', 'presets' => [ 'content-xs', 'content-sm', 'content-md', 'content-lg', 'content-xl', ], ]) ?>
You may als set pictureOptions and imageOptions depending on your needs.
Using the console command
The console command is intended to generate or flush thumbnails for all or just a single preset. If there are no thumbnails, they will be generated on demand (not recommended).
To use it, you need to add the same config to console.php as you did in web.php. However, it is recommended that you place your presets into params.php to keep things clean and consistent.
Additionally, to be able to call the command, define the controller in the controller map:
// ... 'components' => [ // ... 'responsiveImage' => [ // ... ], ], 'controllerMap' => [ // ... 'image' => [ 'class' => 'TomLutzenberger\ResponsiveImage\commands\ImageController', ], ],
Also, you need to define the aliases @web and @webroot in the yii file:
// Put this after the 'require' of the Yii.php Yii::setAlias('@webroot', __DIR__ . '/web'); Yii::setAlias('@web', '/');
tomlutzenberger/yii2-responsive-image 适用场景与选型建议
tomlutzenberger/yii2-responsive-image 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 164 次下载、GitHub Stars 达 1, 最近一次更新时间为 2019 年 12 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「image」 「thumbnail」 「extension」 「responsive」 「yii2」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 tomlutzenberger/yii2-responsive-image 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tomlutzenberger/yii2-responsive-image 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 tomlutzenberger/yii2-responsive-image 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A custom URL rule class for Yii 2 which allows to create translated URL rules
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.
A PHP library for fetching thumbnails from a URL
TYPO3 CMS extension to create gallery content element with preset crop ratios and pagination
UI Kit 3 Extension for Yii2
统计信息
- 总下载量: 164
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-12-05
