iutbay/yii2-imagecache
最新稳定版本:0.2
Composer 安装命令:
composer require iutbay/yii2-imagecache
包简介
ImageCache for Yii2
README 文档
README
Like the Image module in Drupal, this extension will resize your images on demand :-). If a thumb doesn't exist, the web server's rewrite rules will pass the request to Yii which in turn hands it off to ImageCache to dynamically generate the file.
WIP...
Features
- image resize on demand
- text watermark
- image watermark
Installation
The preferred way to install this helper is through composer.
Either run
php composer.phar require "iutbay/yii2-imagecache" "*"
or add
"iutbay/yii2-imagecache" : "*"
to the require section of your application's composer.json file.
Configuration
You should :
- Add
ThumbActionin one of your controller. - Modify your application configuration :
- add imageCache component,
- add url rule to handle request to missing thumbs.
Add ThumbAction
You need to add ThumbAction in one of your controller so that imageCache can handle requests to missing thumbs and create them on demand. You could use site controller :
class SiteController extends Controller { ... public function actions() { return [ ... 'thumb' => 'iutbay\yii2imagecache\ThumbAction', ... ]; } ... }
imageCache component config
You should add imageCache component in your application configuration :
$config = [ 'components' => [ ... 'imageCache' => [ 'class' => 'iutbay\yii2imagecache\ImageCache', 'sourcePath' => '@app/web/images', 'sourceUrl' => '@web/images', //'thumbsPath' => '@app/web/thumbs', //'thumbsUrl' => '@web/thumbs', //'sizes' => [ // 'thumb' => [150, 150], // 'medium' => [300, 300], // 'large' => [600, 600], //], ], ... ], ];
urlManager config
You should enable pretty urls :
http://www.yiiframework.com/doc-2.0/guide-start-installation.html#configuring-web-servers
You should modify your urlManager configuration :
$config = [ 'components' => [ ... 'urlManager' => [ 'enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => [ ... 'thumbs/<path:.*>' => 'site/thumb', ... ], ], ... ], ];
How to use
<?= Yii::$app->imageCache->thumb('@web/images/2014/test.jpg') ?> // <img src="/your-app/thumbs/2014/test_thumb.jpg" alt=""> <?= Yii::$app->imageCache->thumb('@web/images/2014/test.jpg', 'medium') ?> // <img src="/your-app/thumbs/2014/test_medium.jpg" alt=""> <?= Yii::$app->imageCache->thumb('@web/images/2014/test.jpg', 'medium', ['class'=>'img']) ?> // <img src="/your-app/thumbs/2014/test_medium.jpg" alt="" class="img">
iutbay/yii2-imagecache 适用场景与选型建议
iutbay/yii2-imagecache 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 21.31k 次下载、GitHub Stars 达 20, 最近一次更新时间为 2014 年 12 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「image」 「cache」 「resize」 「thumb」 「yii2」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 iutbay/yii2-imagecache 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 iutbay/yii2-imagecache 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 iutbay/yii2-imagecache 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
repository php library
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.
Laravel 5 - Repositories to the database layer
Image cache
The lireincore/imgcache integration for the Yii2 framework
统计信息
- 总下载量: 21.31k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 21
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2014-12-01