LiipImagineBundle: Webp generation broken
With webp settings nothing happening. It generates jpg only.
Preconditions
- PHP 7.4, GD 2.3.0, Imagick 3.5.1, Symfony 5.3.10
- Liip bundle version: 2.7.0
Steps to reproduce
- Install bundle and setup
driver: "gd" # I tried this w/ imagick also but that was not worked also.
resolvers:
default:
web_path: ~
controller:
redirect_response_code: 302
webp:
generate: true
filter_sets:
cache: ~
thumbnail_big:
quality: 75
filters:
thumbnail: { size: [ 800, 450 ], mode: inset }
background: { size: [ 800, 450 ], position: center, color: '#000000' }
thumbnail_small:
quality: 50
format: webp
filters:
thumbnail: { size: [ 90, 50 ], mode: inset }
background: { size: [ 90, 50 ], position: center, color: '#000000' }
- Upload
jpgimages to the system. - Use resolver
use Liip\ImagineBundle\Imagine\Cache\CacheManager;
use Liip\ImagineBundle\Imagine\Data\DataManager;
use Liip\ImagineBundle\Imagine\Filter\FilterManager;
...
private const BIG_FILTER = 'thumbnail_big';
private const SMALL_FILTER = 'thumbnail_small';
public function __construct(
DataManager $dataManager,
FilterManager $filterManager,
CacheManager $cacheManager
) { ... }
...
$urlBig = $this->cacheManager->isStored($path, self::BIG_FILTER)
? $this->cacheManager->resolve($path, self::BIG_FILTER)
: $this->generateUrl(self::BIG_FILTER, $path);
$urlSmall = $this->cacheManager->isStored($path, self::SMALL_FILTER)
? $this->cacheManager->resolve($path, self::SMALL_FILTER)
: $this->generateUrl(self::SMALL_FILTER, $path);
...
private function generateUrl(string $filter, string $picPath): string
{
$image = $this->dataManager->find($filter, $picPath);
$image = $this->filterManager->applyFilter($image, $filter);
$this->cacheManager->store($image, $picPath, $filter);
return $this->cacheManager->resolve($picPath, $filter);
}
Expected result
As I know from documentation, by default there should be .webp images next to the .jpg because the
webp:
generate: true
option. The thumbnail_small filter should only generate webps for thumbnails.
public/media/cache
├── thumbnail_big
│ └── media
│ └── news
│ ├── 1vpWGn-609c1ca783d243.72915944.jpg
│ ├── 1vpWGn-609c1ca783d243.72915944.webp
│ ├── ALkpaA-609cd51b0afa45.56825315.jpg
│ ├── ALkpaA-609cd51b0afa45.56825315.webp
│ ├── ZPQNzq-609c1c99ee1932.95451227.jpg
│ └── ZPQNzq-609c1c99ee1932.95451227.webp
└── thumbnail_small
└── media
└── news
├── 1vpWGn-609c1ca783d243.72915944.webp
├── ALkpaA-609cd51b0afa45.56825315.webp
└── ZPQNzq-609c1c99ee1932.95451227.wepb
Actual result
The generated files are
public/media/cache
├── thumbnail_big
│ └── media
│ └── news
│ ├── 1vpWGn-609c1ca783d243.72915944.jpg
│ ├── ALkpaA-609cd51b0afa45.56825315.jpg
│ └── ZPQNzq-609c1c99ee1932.95451227.jpg
└── thumbnail_small
└── media
└── news
├── 1vpWGn-609c1ca783d243.72915944.jpg
├── ALkpaA-609cd51b0afa45.56825315.jpg
└── ZPQNzq-609c1c99ee1932.95451227.jpg
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 15 (10 by maintainers)
format: webp, remove from configwebp: generate: true, because it’s enforces the use “resolve” URL to detect if browser supports WebP and then provides relevant files.format: webpgeneretes webp files but keeps original extension.Tested on version 2.10.0
I do not have time neither, sorry. But, if anyone facing this issue, there is another bundle for that. It works by itself, and it can be used w/ this bundle.
if somebody has to be time to investigate and propose a fix, i am happy to review it, but i don’t have time to dig into it.
It tested it with 2.6.1 and 2.7.1 and it doesn’t seem to be a BC break. The only caveat is that without
FormatExtensionResolverthe desired format with be saved with the original extension, so for example png/webp saved with a jpg extension.If you’re using
webp.generate: trueanddefault_filter_set_settings.format: pngfor a jpeg image you’ll have a.pngand a.jpg.pngfor the webp image, so somewhere it’s still an issue with the extension.Without
FormatExtensionResolverit saves the webp as.jpg.webp.