Created
April 11, 2018 18:02
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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