Używam liipImagineBundle i próbuję zastosować filtr bezpośrednio do kontrolera.Filtr dynamiczny z liipImagineBundle
W dokumencie znalazłem dwie sekcje, w których wyjaśniono, jak używać liipImagineBundle ze sterownika. Ten 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');
// ..
}
I 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;
}
testowałem jak wskazano w rozdziale „Korzystanie z kontrolera jako usługa” i to działa, problem mam to, że nie wiem, jak uzyskać dostęp do ustawienia filtra, aby je zmodyfikować.
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 }
Po drugie, naprawdę nie rozumiem, kiedy mówi "Za pomocą niestandardowego programu ładującego dane ...".
W tym przykładzie modyfikuje tylko metodę filteraction() z klasy ImagineController (Liip \ ImagineBundle \ Controller). Zastanawiam się, jak mogę dynamicznie modyfikować tę metodę? Na przykład z mojego kontrolera indexAction().
Również przeczytałem ten post https://stackoverflow.com/questions/16166719/loading-your-custom-filters-with-liipimaginebundle gdzie @NSCoder mówi, że "Możesz użyć wbudowanego filtru i zmodyfikować jego konfigurację." ale nie rozumiem tego.
Szukałem od kilku dni, ale nie znalazłem przykładu, od którego można zacząć.