gpt4 book ai didi

image - 带有 liipImagineBundle 的动态过滤器

转载 作者:行者123 更新时间:2023-12-04 15:12:48 28 4
gpt4 key购买 nike

我正在使用 liipImagineBundle 并尝试将过滤器直接应用到 Controller 中。

在文档中,我发现了两个部分,其中解释了如何从 Controller 使用 liipImagineBundle。这个https://github.com/liip/LiipImagineBundle#using-the-controller-as-a-service

public function indexAction()
{
// RedirectResponse object
$imagemanagerResponse = $this->container
->get('liip_imagine.controller')
->filterAction(
$this->getRequest(),
'uploads/foo.jpg', // original image you want to apply a filter to
'my_thumb' // filter defined in config.yml
);

// string to put directly in the "src" of the tag <img>
$srcPath = $imagemanagerResponse->headers->get('location');

// ..
}

https://github.com/liip/LiipImagineBundle/blob/master/Resources/doc/filters.md#dynamic-filters
public function filterAction(Request $request, $path, $filter)
{
$targetPath = $this->cacheManager->resolve($request, $path, $filter);
if ($targetPath instanceof Response) {
return $targetPath;
}

$image = $this->dataManager->find($filter, $path);

$filterConfig = $this->filterManager->getFilterConfiguration();
$config = $filterConfig->get($filter);
$config['filters']['thumbnail']['size'] = array(300, 100);
$filterConfig->set($filter, $config);

$response = $this->filterManager->get($request, $filter, $image, $path);

if ($targetPath) {
$response = $this->cacheManager->store($response, $targetPath, $filter);
}

return $response;
}

我按照“使用 Controller 作为服务”中的说明进行了测试,它可以工作,但我遇到的问题是我不知道如何访问过滤器设置来修改它。
liip_imagine:
driver: gd
web_root: %kernel.root_dir%/../web
data_root: %kernel.root_dir%/../web
cache_mkdir_mode: 0777
cache_prefix: /media/cache
cache: web_path
cache_clearer: true
data_loader: filesystem
controller_action: liip_imagine.controller:filterAction
formats: []
filter_sets:
my_thumb:
filters:
crop: { start: [0, 0], size: [200, 150] }
my_paste:
quality: 90
filters:
paste: { start: [30, 60], image: ../web/uploads/images/firma.jpg }

第二个,真的,我不明白他什么时候说“使用自定义数据加载器......”。

在示例中,他只修改了 ImagineController 类 (Liip\ImagineBundle\Controller) 中的 filteraction() 方法。我想知道如何动态修改该方法?例如来自我的 Controller indexAction()。

我也读过这篇文章 https://stackoverflow.com/questions/16166719/loading-your-custom-filters-with-liipimaginebundle其中@NSCoder 说“您可以使用内置过滤器并修改其配置。”但我不明白。

我已经找了好几天了,但我还没有找到一个可以开始的例子。

最佳答案

寻找更多我发现了另一个 LiipImagineBundle 主题 (Use LiipImagineBundle to Resize Image after Upload?),它帮助我做我想做的事。

在这里我留下我用来动态应用过滤器的代码

public function indexAction()
{

$container = $this->container;

# The controller service
$imagemanagerResponse = $container->get('liip_imagine.controller');

# The filter configuration service
$filterConfiguration = $container->get('liip_imagine.filter.configuration');

# Get the filter settings
$configuracion = $filterConfiguration->get('my_thumb');

# Update filter settings
$configuracion['filters']['crop']['size'] = array(50, 150);
$configuracion['filters']['crop']['start'] = array(10, 10);
$filterConfiguration->set('my_thumb', $configuracion);

# Apply the filter
$imagemanagerResponse->filterAction($this->getRequest(),'uploads/images/logo.jpg','my_thumb');

# Move the img from temp
$fileTemporal = new File('media/cache/my_thumb/uploads/images/logo.jpg');

$fileTemporal->move('uploads/images/', 'mini-logo.jpg');

####################################

}

关于image - 带有 liipImagineBundle 的动态过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16323435/

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