owja/image-proxy-bundle

此包已被弃用,不再维护。没有建议的替代包。

OWJA! 图像代理的基础包

安装: 17

依赖: 0

建议者: 0

安全性: 0

星标: 1

关注者: 1

分支: 0

开放问题: 2

类型:symfony-bundle

0.0.2 2017-07-31 15:25 UTC

This package is not auto-updated.

Last update: 2020-08-19 11:30:18 UTC


README

Latest Stable Version Latest Unstable Version License Build Status

此包是开源的,并遵循MIT许可证。

使用此包,您可以为您的Symfony项目添加一些图像调整大小和优化功能。在设置和配置后,您可以通过此安装访问同一服务器或一个或多个其他服务器上的图像。

访问图像

预设模式

enable_presets 必须设置为 true 以使用此功能。默认为 true

http://.../:preset/imagepath

变量 必需 信息
preset 字符串 预设代码
imagepath 字符串 图像的公共路径

例如,获取由预设 "fullhd" 处理的图像 "img/someimage.jpg" 的示例:http://example.com/:fullhd/img/someimage.jpg

动态模式

enable_dynamic 必须设置为 true 以使用此功能。默认为 false

重要!动态模式不应在生产环境中使用!

http://.../type/heightxwidth/imagepath

变量 必需 信息
类型 resizecrop 调整大小首先将图像调整到最佳尺寸,然后裁剪到目标大小。
高度 整数 图像的目标高度
宽度 整数 图像的目标宽度
imagepath 字符串 图像的公共路径

示例

将图像调整大小并裁剪以适应 100x100 像素的正方形

http://example.com/resize/100x100/img/someimage.jpg

裁剪以适应 100x100 像素的正方形

http://example.com/resize/100x100/img/someimage.jpg

调整大小到 100 像素宽并保持原始图像比例

http://example.com/resize/x100/img/someimage.jpg

调整大小到 100 像素高度并保持原始图像比例

http://example.com/resize/100x/img/someimage.jpg

仅优化

http://example.com/resize/x/img/someimage.jpg

安装

$ composer require owja/image-proxy-bundle

app/AppKernel.php 中加载包

new Oneup\FlysystemBundle\OneupFlysystemBundle(),
new Owja\ImageProxyBundle\OwjaImageProxyBundle(),

设置 app/config/config.yml

oneup_flysystem:
    adapters:
        image_cache_adapter:
            local:
                directory: "%kernel.root_dir%/../var/images"

    filesystems:
        image_cache_filesystem:
            adapter: image_cache_adapter
            alias: owja_image_proxy.cache

owja_image_proxy:
    sites:
        default:
            url: "http://example.com/"

将 "http://example.com/" 设置为表示您图像源的URL。

设置 app/config/routing.yml

owja_image_proxy:
    resource: "@OwjaImageProxyBundle/Controller/"
    type:     annotation
    prefix:   /

创建在处理图像时创建的临时文件目录

var/temp

配置详情

owja_image_proxy:
    remote:
        token: null
        timeout: 10
    limits:
        height: 1080
        width: 1920
    temp_dir: "%kernel.root_dir%/../var/temp/"
    cache_service: "owja_image_proxy.cache"
    optimization: true
    default_site: default
    enable_sites: false
    enable_dynamic: false
    enable_presets: true
CVar 默认 信息
remote : token null 通过 Header 'owja-image-proxy' 发送
remote : timeout 10 获取源图像的请求超时
limits : height 1080 请求图像允许的最大高度
limits : width 1920 请求图像允许的最大宽度
temp_dir "%kernel.root_dir%/../var/temp/" 图像处理的临时目录
cache_service "owja_image_proxy.cache" 缓存文件系统名称(oneup_flysystem)
optimization true 启用/禁用图像优化
default_site "default" 默认站点的代码。必须在站点下配置
enable_sites false 设置为true以启用除默认站点之外的站点
enable_dynamic false 设置为true以启用动态模式
enable_presets true 设置为true以启用处理预定义预设

多个站点

只需添加一些站点并将enable_sites设置为true

owja_image_proxy:
    enable_sites: true
    sites:
        default:
            url: "http://example.com/"
        othersite:
            url: "http://othersite.com/"
        whereever:
            url: "http://wherever.com/"

按站点访问图像

与上面解释的相同("访问图像"),但带有站点参数

动态模式

http://.../site/type/widthxheight/imagepath

http://example.com/default/resize/100x100/images/someimage.jpg
http://example.com/othersite/resize/100x100/images/someimage.jpg
http://example.com/wherever/resize/100x100/images/someimage.jpg

预设模式

http://.../site:preset/imagepath

http://example.com/default:fullhd/images/someimage.jpg
http://example.com/othersite:fullhd/images/someimage.jpg
http://example.com/wherever:fullhd/images/someimage.jpg

预设配置

全局预设

owja_image_proxy:
    enable_presets: true
    presets:
        fullhd:
            width: 1920
            height: 1080
        banner:
            width: 1600
        profile:
            height: 50
            width: 50
        cuthd:
            width: 1280
            height: 720
            type: crop            

站点特定预设

owja_image_proxy:
    enable_presets: true
    sites:
        default:
            url: "http://example.com/"
            presets:
                fullhd:
                    width: 1920
                    height: 1080
        whereever:
            url: "http://whereever.com/"
            presets:
                banner:
                    width: 1600
                    height: 200
        

图像优化

要启用图像优化,您应该安装一些优化器。

# Ubuntu 16.04 LTS
apt install gifsicle jpegoptim pngquant optipng

如果您已安装了优化器但想禁用优化,您可以在app/config/config.yml中这样做

owja_image_proxy:
    optimization: false

报告 & 协作

问题和功能请求在此GitHub问题跟踪器中跟踪。用于增强代码以添加功能或修复错误的拉取请求非常欢迎。:-)

许可证

此捆绑包受MIT许可证的约束。