gpt4 book ai didi

symfony - (Symfony 4) 如何从 PHP 代码中访问 Liip Imagine 包?

转载 作者:行者123 更新时间:2023-12-02 17:00:05 24 4
gpt4 key购买 nike

我希望能够上传一个文件,并从中创建 3 个缩略图并将所有内容存储在 S3 服务器上。

我的 liip/LiipImagineBundle 设置如下:

liip_imagine :

# configure resolvers
resolvers :

# setup the default resolver
default :

# use the default web path
web_path : ~

# your filter sets are defined here
filter_sets :

# use the default cache configuration
cache : ~

# the name of the "filter set"
my_thumb :

# adjust the image quality to 75%
quality : 75

# list of transformations to apply (the "filters")
filters :

# create a thumbnail: set size to 120x90 and use the "outbound" mode
# to crop the image when the size ratio of the input differs
thumbnail : { size : [120, 90], mode : outbound }

# create a 2px black border: center the thumbnail on a black background
# 4px larger to create a 2px border around the final image
background : { size : [124, 94], position : center, color : '#000000' }

# the name of the "filter set"
thumb_square :

# adjust the image quality to 75%
quality : 75

# list of transformations to apply (the "filters")
filters :

thumbnail : { size : [300, 300], mode : outbound }

# create a 2px black border: center the thumbnail on a black background
# 4px larger to create a 2px border around the final image
background : { size : [304, 304], position : center, color : '#000000' }

# the name of the "filter set"
thumb_rectangle_md :

# adjust the image quality to 75%
quality : 75

# list of transformations to apply (the "filters")
filters :

thumbnail : { size : [670, 400], mode : outbound }

# create a 2px black border: center the thumbnail on a black background
# 4px larger to create a 2px border around the final image
background : { size : [674, 404], position : center, color : '#000000' }

# the name of the "filter set"
thumb_hd :

# adjust the image quality to 75%
quality : 75

# list of transformations to apply (the "filters")
filters :

thumbnail : { size : [1920, 1080], mode : outbound }

# create a 2px black border: center the thumbnail on a black background
# 4px larger to create a 2px border around the final image
background : { size : [1924, 1084], position : center, color : '#000000' }

这是我正在查看的文档:https://symfony.com/doc/2.0/bundles/LiipImagineBundle/basic-usage.html#runtime-options

我遇到的问题是,在文档中它只是说要像下面这样:

$this['imagine']->filter('/relative/path/to/image.jpg', 'my_thumb')

我得到的明显错误是:

不能将 App\Controller\CreatorDashboard\PostsController 类型的对象用作数组

我明白为什么我会收到错误,它认为我正在尝试将我的 Controller 类用作数组。

但是你如何在代码中访问这个 Liip/LiipImagineBundle 呢?我如何在 Symfony 4 中获得它的“句柄”?

文档不清楚。

最佳答案

您分享的示例是针对没有 Twig 的模板用法。如果您在 Controller 中(基于您共享的错误的假设),您需要将 Liip 缓存管理器从容器中取出。

/** @var CacheManager */
$imagineCacheManager = $this->get('liip_imagine.cache.manager'); // gets the service from the container

/** @var string */
$resolvedPath = $imagineCacheManager->getBrowserPath('/relative/path/to/image.jpg', 'my_thumb'); // resolves the stored path

关于symfony - (Symfony 4) 如何从 PHP 代码中访问 Liip Imagine 包?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54543563/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com