我正在使用liipImagineBundle,並試圖將過濾器直接應用到控制器中。liipImagineBundle動態過濾器
在文檔中,我找到了兩節介紹如何使用控制器中的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;
}
我測試如「使用控制器即服務」的指示和它的作品,我的問題是,我不知道如何訪問過濾器設置來修改它。
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()。我想知道如何動態修改該方法?例如從我的控制器indexAction()。
另外我已閱讀此帖https://stackoverflow.com/questions/16166719/loading-your-custom-filters-with-liipimaginebundle其中@NSCoder表示「您可以使用內置過濾器並修改其配置。」但我不明白。
我一直在尋找幾天,但我還沒有找到一個從哪個例子開始。