letyii / yii2-imagecache
Image cache for yii2
Installs: 1 526
Dependents: 1
Suggesters: 0
Security: 0
Stars: 6
Watchers: 4
Forks: 5
Open Issues: 2
Requires
- php: >=5.4
- yiisoft/yii2: *
- yiisoft/yii2-imagine: *
This package is not auto-updated.
Last update: 2024-11-13 10:02:59 UTC
README
Features
- Image resize on demand
- Imagick support
- GD support
- Amazon S3 support
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require "letyii/yii2-imagecache" "*"
or add
"letyii/yii2-imagecache": "*"
to the require section of your application's composer.json
file.
Config
'components' => [ ... 'imageCache' => [ 'class' => 'letyii\imagecache\imageCache', 'cachePath' => '@app/uploads/cache', 'cacheUrl' => '@web/uploads/cache', ], ]
Usage Example
echo Yii::$app->imageCache->imgSrc('@app/uploads/test.jpg', 'x200'); // Output: /your-app/uploads/cache/x200/.../test.jpg echo Yii::$app->imageCache->img('@app/uploads/test.jpg', '100x'); // Output: <img src="/your-app/uploads/cache/100x/.../test.jpg" alt="" /> echo Yii::$app->imageCache->img('@app/uploads/test.jpg', '100x150', ['class'=>'test', 'alt' => 'Test image']); // Output: <img src="/your-app/uploads/cache/100x120/.../test.jpg" alt="" class="img" alt="Test image" />