novactive/ezcloudinarybundle

Novactive eZ Cloudinary Bundle 是一个用于图像优化和处理的 eZPlatform 扩展包。

安装数量: 1,133

依赖: 0

推荐者: 0

安全: 0

星标: 3

关注者: 13

分支: 5

开放问题: 0

类型:ezplatform-bundle

1.0.0 2020-08-25 21:23 UTC

This package is auto-updated.

Last update: 2024-09-19 12:04:28 UTC


README

这个仓库被称为“子树分割”:主仓库中一个目录的只读副本。Composer 使用它允许开发者依赖特定的扩展包。

如果您想报告或贡献,请转而打开主仓库的问题:https://github.com/Novactive/Nova-eZPlatform-Bundles

文档可通过此仓库中的 .md 文件获取,但还打包在此:https://novactive.github.io/Nova-eZPlatform-Bundles/master/CloudinaryBundle/README.md.html

Downloads Latest version License

Novactive eZ Cloudinary Bundle 是一个用于图像优化和处理的 eZPlatform 扩展包。

这个扩展包将 Cloudinary 的功能引入到您的 eZ Platform 项目中。

对于这个第一个版本,插件允许您在 eZ Variations 的基础上定义 Cloudinary 变体。图像仍保留在您的服务器上,但源 (SRC) 被调整为使 Cloudinary 渲染/处理图像。

所有配置都是 SiteAccessAware,因此您可以根据 SiteAccess 使用不同的配置。

安装

使用 Composer

将库添加到您的 composer.json 中,运行 composer require novactive/ezcloudinarybundle 以刷新依赖关系。

然后,将扩展包注入到您的应用程序的 bundles.php 中。

    Novactive\Bundle\eZCloudinaryBundle\NovaeZCloudinaryBundle::class => [ 'all'=> true ],

设置您的凭证

nova_ezcloudinary:
    authentification:
        cloud_name: 'demo'
        api_key: "xxxxx"
        api_secret: "xxxx"

用法

此扩展包模拟了原生图像变体系统。

parameters:
    nova_ezcloudinary.default.cloudinary_variations:
            simpletest1:
                ezreference_variation: 'Native eZ Variation Name, ~ means original'
                filters: # look at the documentation on Cloudinary
                    width: 200
                    height: 200
                    gravity: 'face'
                    radius: 'max'
                    effect: 'sepia'
            simpletest2: # look at the documentation on Cloudinary
                ezreference_variation: 'medium' # Cloudinary manipulation are going to be base on the medium alias
                filters: # look at the documentation on Cloudinary
                    transformation:
                        width: 300
                        height: 300
                        effect: 'sepia'
                        radius: 'max'
                        fetch_format: 'auto'
                        angle: 45

在您的模板中

    {{ ez_render_field( content, "image",{
        "parameters": {"alias": 'simpletest2'},
        "attr" : { "class" : "img-responsive" }
    }
    ) }}

自动使用 nova_ezcloudinary_alias 而不是 ez_image_alias。如果别名名称不在 cloudinary_variations 中,扩展包将回退到原生变体系统。

然后,基本上您的代码没有变化,只需为您的变体配置 yaml。

如果您已覆盖内容字段,请确保更新对 nova_ezcloudinary_alias 的调用

链式转换

可以通过向配置中添加数组来执行链式转换

filters:
  transformation:
    - secure: 'true'
      crop: 'crop'
      height: 823
      width: 1920
      quality: 'auto:best'
    - crop: 'crop'
      y: 0
      x: 415
      width: 1234
      height: 823
      quality: 'auto:best'
    - crop: 'scale'
      width: 537
      height: 358
      aspect_ratio: '3:2'
      quality: 'auto:eco'

本地模式

此扩展包使用 Cloudinary 的抓取模式,因此图像必须是“可访问”的才能进行转换。但是,显然您的本地主机不是公开的,为了绕过这种情况,我们推荐使用 ngrok

假设您的 web 服务器监听 TCP 端口 42080

$ ngrok http 42080

您将得到类似 http://xxxxx.ngrok.io 的结果,您可以在配置中设置它

parameters:
    nova_ezcloudinary.default.cloudinary_fecth_proxy:
        host: xxxxx.ngrok.io

您也可以自己设置隧道,但 ngrok 在此方面做得非常好

不带 Cloudinary 的本地模式

您还可以禁用所有 Cloudinary 变体以供本地使用,仅使用原生的 ezplatform 变体。

parameters:
    nova_ezcloudinary.default.cloudinary_disabled: true
    nova_ezcloudinary.default.cloudinary_fallback_variation: original # Will replace all unknown variation by original