liip imagine_filter in Symfony Controller on non public path

347 Views Asked by At

Is there any way to use liip imagine_filter without copying the image source to a public path? I can not see how resolvers/loaders have to be set up to load images from a non public file location and store them likewise.

I defined a watermark filter with a watermark image placed outside public path - which works without problems. But ONLY applied on images placed IN public path.

I am on Symfony 5 and "liip/imagine-bundle": "^2.6"

1

There are 1 best solutions below

0
On

I have the same problem as you and i found this solution, of course is a little workaround but it works very well. So I copy the file from $remoteWatermak into the server. if the $localWatermark is setted I check if the file exist.

$arrContextOptions=array(
    "ssl"=>array(
        "verify_peer"=>false,
        "verify_peer_name"=>false,
    ),
);

if($localWatermark){

    $filesystem = new Filesystem();
    if(!$filesystem->exists($localWatermark)){
        $contents = file_get_contents($remoteWatermark,false,
            stream_context_create($arrContextOptions)); // get file

        file_put_contents($localWatermark , $contents);

    }

}else{
    $contents = file_get_contents($remoteWatermark,false,
        stream_context_create($arrContextOptions)); // get file

    $file = "uploads/watermarks/" . uniqid();
    file_put_contents($file , $contents);

    $localWatermark = $file;
}