EDIT: to cut this short: is there a way to call $kernel->getRootDir(); from within a twig extension? Or maybe from the DI container?
ORIGINAL QUESTION:
I try to scale images on the server by using Imagine. Everything works fine as log as I don't try to trigger the rendering via command line: In this case it looks like there is a wrong path set- I'm getting an error:
[Twig_Error_Runtime]
An exception has been thrown during the rendering of a template ("File ../web/documents/4f59ef3f76e74_test3.jpg doesn't exist") in "....:detail.html.twig" at line 72.
I'm using a twig tag which I wrote by myself:
public function thumbnail($path,$width,$maxHeight=0,$alt="",$absolute=false){
/* @var $imagine \Imagine\Gd\Imagine */
$imagine = $this->container->get('imagine');
//$box = new \Imagine\Image\Box($width, $height);
/* @var $image \Imagine\Image\ImageInterface */
$image = $imagine->open("../web/".$path);
...
I also tried this (both works when I render the template via browser request)
$image = $imagine->open($path);
$path is set to "documents/4f59ef3f76e74_test3.jpg" "documents/" is a sub directory of "web"
Any ideas?
Ha- found it! This retrieves the absolute system file path of the web folder:
$webRoot = $this->container->get('kernel')->getRootDir()."/../web";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With