Use SVG Images with glide
Hi, I'm trying to use glide with svg Image.
I add this to twill.php
'glide' => [
'original_media_for_extensions' => ['svg'],
'default_params' => [
'fm' => 'png',
'q' => '100',
'auto' => 'compress,format',
'fit' => 'min',
],
'lqip_default_params' => [
'fm' => 'webp',
'auto' => 'compress',
'blur' => 100,
'dpr' => 1,
],
],
With this I can see in backend the correct image (PIC 1)
So now i'm trying to use it in frontend
$world_image = $page
->imageObjects('world_image', 'default')
->map(function ($media) use ($page) {
return @TwillImage::make($page, 'world_image', $media)->crop('default');
})->toArray();
foreach ($world_image as $k => $image) {
if (isset($image['image']['src'])) {
$data['img'] = $image['image'];
break;
}
When I try this with SVG image i Have this error (with cron and uncropped image)
DivisionByZeroError thrown with message "Division by zero"
Stacktrace:
#57 DivisionByZeroError in /Users/mikmella/Sites/vendor/area17/twill-image/src/Services/MediaSource.php:276
#56 A17\Twill\Image\Services\MediaSource:aspectRatio in /Users/mikmella/Sites/vendor/area17/twill-image/src/Services/MediaSource.php:315
#55 A17\Twill\Image\Services\MediaSource:toArray in /Users/mikmella/Sites//vendor/area17/twill-image/src/Models/Image.php:281
...
If I use a png or jpg image all works fine!
Someone can help me?
Thank you![](https://utfs.io/f/b4efccd2-5a88-46ff-b2a2-a55309622ed6-2c3lql.29.02.png)
![](https://utfs.io/f/4552cd41-534d-4cc4-bab2-42e2ab654bd1-2c3lql.30.22.png)
5 Replies
Hi @Sami if you're looking to render as SVG, I don't think Twill image is suitable or necessary, as it will be trying to compute responsive sets. I think you can submit an issue to twill-image though, as we should take
original_media_for_extension
into consideration to avoid this error.Hi @ifox. Thanks for your tip. Will write it down for my future coding so I'm ready when the situation comes. Until then I'm tagging @Kormi so he can also read this answer.
oops sorry I tagged the wrong person, thanks @Sami
Thank You @Sami
So How can I get url of an uploaded svg?
ImageService::getRawUrl($media->uuid)