Skip to content

Instantly share code, notes, and snippets.

@teohhanhui
Created April 11, 2018 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teohhanhui/cc0d1913d5d0ef3b4c20a51369732d71 to your computer and use it in GitHub Desktop.
Save teohhanhui/cc0d1913d5d0ef3b4c20a51369732d71 to your computer and use it in GitHub Desktop.
Fix SVG in LiipImagineBundle (use together with https://gist.github.com/teohhanhui/90bbc4a61888ad2e92a160d8459db300 to fix MIME type in Symfony)
<?php
declare(strict_types=1);
namespace AppBundle\Imagine\Filter;
use Liip\ImagineBundle\Binary\BinaryInterface;
use Liip\ImagineBundle\Imagine\Filter\FilterManager as BaseFilterManager;
use Liip\ImagineBundle\Model\Binary;
class FilterManager extends BaseFilterManager
{
/**
* {@inheritdoc}
*/
public function apply(BinaryInterface $binary, array $config): Binary
{
if ('svg' === $binary->getFormat() && !isset($config['format'])) {
$config['format'] = 'png';
}
return parent::apply($binary, $config);
}
}
parameters:
# ...
services:
# ...
AppBundle\Imagine\Cache\Resolver\WebPathResolver:
decorates: liip_imagine.cache.resolver.default
parent: liip_imagine.cache.resolver.default
autowire: true
autoconfigure: false
public: true
AppBundle\Imagine\Filter\FilterManager:
decorates: liip_imagine.filter.manager
parent: liip_imagine.filter.manager
autowire: true
autoconfigure: false
public: true
<?php
declare(strict_types=1);
namespace AppBundle\Imagine\Cache\Resolver;
use Liip\ImagineBundle\Imagine\Cache\Resolver\WebPathResolver as BaseWebPathResolver;
class WebPathResolver extends BaseWebPathResolver
{
/**
* {@inheritdoc}
*/
protected function getFileUrl($path, $filter): string
{
$path = preg_replace('/\.svg$/', '.png', $path);
return parent::getFileUrl($path, $filter);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment