mezcalito/imgproxy-bundle

安装: 146

依赖: 0

建议: 0

安全: 0

星标: 7

关注者: 5

分支: 0

公开问题: 0

类型:symfony-bundle

0.2.0 2024-01-08 07:31 UTC

This package is auto-updated.

Last update: 2024-09-08 08:58:18 UTC


README

此包为基于Symfony的项目提供imgproxy集成。

安装

在终端运行此命令

composer require mezcalito/imgproxy-bundle

如果您不使用Symfony Flex,您必须手动在应用程序中启用此包

<?php

return [
    // ...
    Mezcalito\ImgproxyBundle\ImgproxyBundle::class => ['all' => true]
];

基本用法

此包通过在模板或代码中对图片应用预设来工作。您的预设定义在应用程序的配置文件中(/config/packages/imgproxy.yaml)。

目前,此包只提供了一个预设:resize预设。以后将添加更多功能。

要使用此包,创建以下文件

# config/packages/imgproxy.yaml

imgproxy:
    host: localhost
    media_url: https://media.localhost

    # set the same key and salt in imgproxy environment (https://docs.imgproxy.net/signing_the_url)
    signature:
        key: c27f2c1d
        salt: fa242e79

    # default settings applied for all presets
    default_preset_settings:
        format: webp
        encode: true

    presets:
        # this is a preset example with all the configuration available
        png_thumbnail:
            format: png
            resize:
                resizing_type: fit
                width: 150
                height: 75
                enlarge: true
                extend:
                    extend: true
                    gravity:
                        type: no
                        x_offset: 10
                        y_offset: 10

然后,您可以在模板中使用您的预设

<img src="{{ asset('/relative/path/to/image.jpg') | imgproxy_preset('png_thumbnail') }}" />

问题和功能请求

请在https://github.com/mezcalito/imgproxy-bundle/issues处报告问题和请求功能。

许可证

此包遵循MIT许可证。有关完整版权信息,请参阅与此源代码一起分发的LICENSE文件。