lireincore / imgcache-bundle
为 Symfony 框架提供的 lireincore/imgcache 集成
0.4.0
2019-11-10 13:49 UTC
Requires
- lireincore/imgcache: ^0.6
- symfony/config: ^3.4 || ^4.0
- symfony/dependency-injection: ^3.4 || ^4.0
- symfony/http-kernel: ^3.4 || ^4.0
Requires (Dev)
- phpunit/phpunit: ^7
- roave/security-advisories: dev-master
README
关于
Symfony 框架的 lireincore/imgcache 集成。
安装
将 "lireincore/imgcache-bundle": "^0.4"
包添加到 composer.json
文件的 require
部分
或者
$ php composer.phar require lireincore/imgcache-bundle
使用方法
要使用此包,您需要在 config/packages
文件夹中创建 lireincore_imgcache.yaml
文件,并将以下模板粘贴进去
# config/packages/lireincore_imgcache.yaml lireincore_imgcache: srcdir: '%kernel.project_dir%/files' destdir: '%kernel.project_dir%/public/thumbs' webdir: '%kernel.project_dir%/public' presets: origin: effects: - { type: 'resize', params: { width: '50%', height: 100 } } - 'grayscale'
添加监听类并配置事件处理,以便在创建缩略图时(需要 symfony/event-dispatcher: ^4.3
或其他 psr-14 兼容的事件派发器)
# config/services.yaml services: Psr\EventDispatcher\EventDispatcherInterface: '@event_dispatcher' App\Event\ThumbCreatedListener: tags: - { name: kernel.event_listener, event: LireinCore\ImgCache\Event\ThumbCreatedEvent, method: onThumbCreated }
有关可用的效果和其他配置选项的更多信息,请参阅 lireincore/imgcache
的 README.md
在您的代码中使用
$imgcache = $this->container->get('lireincore_imgcache.service.imgcache'); // get thumb url for image '{srcdir}/blog/image.jpg' (preset 'origin') $url = $imgcache->url('blog/image.jpg', 'origin');
有关可用的函数的更多信息,请参阅 lireincore/imgcache
的 README.md
许可证
本项目采用 MIT 许可证 - 详细信息请参阅 许可证文件