CUstom data loader for using remote images
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 1.7k
- Forks
- 386
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 3
Description
Preconditions
- PHP 8.1
- Symfony 5.4
- Last version of Liips bundle
- GD library
Steps to reproduce
I try to create my own custom data loader to apply filters with remote images.
In the file services.yaml
app.imagine.cdn_data_loader:
class: App\Domain\RemoteStreamLoader
arguments:
- '@liip_imagine'
tags:
- { name: 'liip_imagine.binary.loader', loader: 'cdn_data_loader' }
Then the file RemoteStreamLoader.php
use App\Domain;
use Liip\ImagineBundle\Binary\Loader\LoaderInterface;
use Imagine\Image\ImagineInterface;
class RemoteStreamLoader implements LoaderInterface
{
protected $imagine;
public function __construct(ImagineInterface $imagine)
{
\dump($imagine); die();
$this->imagine = $imagine;
}
public function find($path)
{
\dump("find"); die();
// The http:// becomes http:/ in the url path due to how routing urls are converted
// so we need to replace it by http:// in order to load the remote file
$path = preg_replace('@\:/(\w)@', '://$1', $path);
return $this->imagine->load(file_get_contents($path));
}
}
Then my liips filter configuration :
liip_imagine:
# valid drivers options include "gd" or "gmagick" or "imagick"
driver: "gd"
data_loader: "cdn_data_loader"
# configure resolvers
resolvers:
# setup the default resolver
default:
# use the default web path
web_path: ~
filter_sets:
# use the default cache configuration
cache: ~
# name our filter set "my_thumb_filter"
thumbnail_filter:
filters:
# use and setup the "thumbnail" filter
thumbnail:
# set the thumbnail size to "32x32" pixels
size: [32, 32]
# crop the input image, if required
mode: outbound
And then I use the filter in Twig view
<img src="{{ ImageUrlPath | imagine_filter('thumbnail_filter') }}" class="rounded-circle" />
Expected result
The image does not appear and my custom data filter RemoteStreamLoader is not called
What is wrong ?
Thanks,
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the service definition in services.yaml through RemoteStreamLoader.php, then verify how the Twig imagine_filter call selects the configured data loader. Reproduce the Symfony 5.4 setup with the shown GD configuration and determine why find() is not reached. Done means the remote-image filter path invokes the custom loader or the issue clearly documents the required configuration change.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php, symfony
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100