getherbie / plugin-imagine
此包已被废弃且不再维护。未建议替代包。
Herbie Imagine 插件。
v1.0.0
2016-04-05 15:02 UTC
Requires
- getherbie/herbie: ^1.0.0
This package is auto-updated.
Last update: 2023-01-02 19:25:46 UTC
README
注意:自2.x版本起,此插件成为Herbie的一部分,请参阅https://github.com/getherbie/herbie/tree/2.x/plugins/imagine。
Herbie Imagine 插件
Imagine
是一个 Herbie 插件,它将同名图像处理 OOP 库 Imagine 集成到您的网站中。
借助 Imagine,您可以直接编辑图片并应用预设的滤镜和效果。Imagine 是一个面向对象的图像处理库,它基于精心设计的架构,同时采用了最新的最佳实践。
安装
您可以通过 Composer 安装此插件。
$ composer require getherbie/plugin-imagine
然后,在配置文件中激活插件。
plugins:
enable:
- imagine
配置
在 plugins.config.imagine
下,您有以下选项可供选择
# template path to twig template
template: @plugin/disqus/templates/disqus.twig
# enable shortcode
shortcode: true
# enable twig function and filter
twig: false
# filter set definition
filter_sets:
...
配置滤镜
为了在 Herbie 中使用 Imagine,必须为每个项目调整配置。在此过程中,可以定义一个或多个滤镜集,每个滤镜集包含一个或多个滤镜。以下是一个配置示例,其中我们创建了两款简单的滤镜,用于缩放和裁剪图片。
# define filter sets for use in shortcode
filter_sets:
# define resize filter
resize:
filters:
thumbnail:
size: [280, 280]
mode: inset
# define drop filter
crop:
filters:
crop:
start: [0, 0]
size: [560, 560]
使用此配置,您将有两个 Imagine 滤镜 resize
和 crop
可用于在页面内容中的应用。
以下代码将图片缩放到最大尺寸 280 x 280 像素:
[imagine mein-bild.jpg filter="resize"]
以下代码将图片裁剪到 560 x 560 像素:
[imagine mein-bild.jpg filter="crop"]
通过启用 Twig,您可以在布局文件中同时作为函数和过滤器使用 Imagine
# Twig-Funktion
{{ imagine(path="mein-bild.jpg", filter="bsp1") }}
# Twig-Filter
{{ "mein-bild.jpg" | imagine("bsp1") }}
参数
- path / 字符串 / 必需的
- filter / 字符串 / 必需的
- alt / 字符串
- class / 字符串
- id / 字符串
- style / 字符串
- title / 字符串
- width / 整数 / 默认 0
- height / 整数 / 默认 0,
- media / 整数 / 1