I try to convert a image with the LiipImagineBundle. The file is stored in a subfolder storage/
in the symfony app root folder and not in the web/
folder. This is because I have to wite a custom security layer before the delivery of the images.
For example I have a image in the folder symfony_app/storage/images/image.jpg
. Now I want to convert it and save the filtered image in the subfolder symfony_app/storage/images/thumbnail/image.jpg
.
Now I try the code
$imagineController = $this->container->get('liip_imagine.controller');
$imagineController->filterAction(new Request(), '/path/to/symfony_app/storage/images/image.jpg', 'thumbnail');
but I get an 404 error with the message "Source image could not be found"
.
I don't understand why the file could not be found. I also tried the console command
php bin/console liip:imagine:cache:resolve images/image.jpg
and get the result:
[Imagine\Exception\RuntimeException]
Unable to open image /path/to/symfony_app/storage/images/image.jpg
The storage/
subfolder has the access rights 777 and this is my LiipImagine configuration:
liip_imagine:
loaders:
default:
filesystem:
data_root: /var/www/actus-backend/storage/
resolvers:
default:
web_path: ~
filter_sets:
cache: ~
thumbnail:
quality: 75
filters:
thumbnail: { size: [100, 100], mode: outbound }
Try setting your storage path using the kernel.root_dir
parameter.
If you need the path to the secure images folder in your security layer it may be helpful to define it as parameter. Reuse that parameter in the configuration for the LiipImagine bundle:
# app/config/config.yml
parameters:
images_root_dir: "%kernel.root_dir%/../storage"
liip_imagine:
loaders:
default:
filesystem:
data_root: "%images_root_dir%"