hrevert / ht-img-module
适用于 Zend Framework 2 的图像处理模块
0.6.0
2018-04-27 19:07 UTC
Requires
- php: ^5.6 || ^7.0
- imagine/imagine: ^0.7.1
- symfony/http-foundation: ~3.4
- zendframework/zend-eventmanager: ^2.7 || ^3.0
- zendframework/zend-http: ^2.5
- zendframework/zend-modulemanager: ^2.6
- zendframework/zend-mvc: ^2.7.10 || ^3.0
- zendframework/zend-servicemanager: ^2.7.6 || ^3.1
- zendframework/zend-stdlib: ^2.7 || ^3.0
Requires (Dev)
- ext-gd: *
- doctrine/instantiator: 1.0.5
- knplabs/gaufrette: ^0.1.9
- league/flysystem: 0.4.*
- phine/test: 1.*
- phpunit/phpunit: ^5.7
- zendframework/zend-escaper: ^2.2
- zendframework/zend-filter: ^2.5
- zendframework/zend-view: ^2.7
Suggests
- knplabs/gaufrette: To use this library to load image
- league/flysystem: To use this library to load image
- zendframework/zend-view: To use some view helpers provided this module
This package is auto-updated.
Last update: 2024-09-13 02:43:46 UTC
README
本模块简化了 Zend Framework 的图像处理。此模块将 zf2/zf3 与最令人惊叹的 PHP 图像处理库 Imagine 集成。
安装
composer require hrevert/ht-img-module
- 在
config/application.config.php
中注册HtImgModule
为模块 - 将位于
vendor/hrevert/ht-img-module/config/ht-img-module.global.php
的文件复制到config/autoload
并根据需要进行更改
基本用法
首先,您需要在 /module/Application/config/module.config.php
中创建一个过滤器服务,例如 my_thumbnail
return [ 'htimg' => [ 'filters' => [ 'my_thumbnail' => [ // this is filter service 'type' => 'thumbnail', // this is a filter loader 'options' => [ // filter loader passes these options to a Filter which manipulates the image 'width' => 100, 'height' => 100, 'format' => 'jpeg' // format is optional and defaults to the format of given image ] ] ] ] ];
现在,您可以从视图模板中获取图像,例如
<img src="<?php echo $this->htImgUrl('my_image.png', 'my_thumbnail'); ?>" alt="Hello" />
或者,您也可以
<?php echo $this->htDisplayImage('my_image.png', 'my_thumbnail', ['alt' => 'Hello']); ?>
在幕后,模块会在第一次请求时对图像应用过滤器,然后将图像缓存到网站根目录。在下一个请求中,缓存图像将直接从文件系统提供服务。
工作原理
每当您从视图模板调用过滤器服务(如 my_thumbnail
),视图辅助函数(htImgUrl 和 htDisplayImage)会检查缓存图像是否存在。如果缓存图像存在,它将直接返回缓存图像的 URL。否则,它将返回显示图像的 URL。同时,在网站根目录中创建一个新的缓存图像!
文档
官方文档位于 docs/ 目录中
致谢
HtImgModule 受 AvalancheImagineBundle 和 LiipImagineBundle 的启发。