liip / LiipImagineBundle

Symfony Bundle to assist in image manipulation using the imagine library
http://liip.ch
MIT License
1.66k stars 378 forks source link

Document how to resolve source image path #1523

Open tacman opened 1 year ago

tacman commented 1 year ago

I would like to get the absolute path of the source image before calling the liip resolver (with the relative path to the image), so that if the image is not there I can dispatch a request to download it.

But I can't figure out how to get that path without re-creating the logic that exists in the Liip Imagine service.

That is, I can get the browser path:

            $url = $this->imageCacheManager->getBrowserPath($relativePath, $filter,
                referenceType: UrlGenerator::ABSOLUTE_PATH
            );

What I want is to get the absolute path.

            $path = $this->imageCacheManager->getSourcePath($relativePath);
            if (!file_exists($path)) $this->downloadImage($relativePath);

I realize that file_exists should be replaced with the Flysystem call, so I guess what may be needed is a way to get the filesystem.

    loaders:
        flysystem_loader:
            flysystem:
                # this comes from flysystem.yaml
                filesystem_service: images_filesystem

    # default loader to use for all filter sets
    data_loader: flysystem_loader
            $loader = $this->imageCacheManager->getLoader();
            // 
            $path = $this->imageCacheManager->getSourcePath($relativePath);
            if (!$loader->fileExists($path)) $this->downloadImage($relativePath);

I've poked around in the code, but the methods I see are private. Is there a way to get what I'm looking for? Since I'm using the local filesystem, I can hack in something that uses the same path that's defined in Flysystem, but that seems precarious.