Voyager: cannot upload photos with .svg extension

Created on 7 Nov 2019  路  3Comments  路  Source: the-control-group/voyager

  • Laravel: v5.8.0
  • Voyager: v1.2.0
  • PHP: v7.1.3
  • Database: Driver

When I'm trying to upload images with .svg extension voyager I have this message:
Unsupported image type. GD driver is only able to decode JPG, PNG, GIF or WebP files.

possible bug

Most helpful comment

@MrCrayon I've added a check for the mime type before resizing the image and allows SVG to be uploaded.
Could you please check I've committed it correctly.
https://github.com/the-control-group/voyager/commit/ea9c21577d885a9afdbfb15416ac92be627779c9

All 3 comments

Please when opening an issue state the full version as the issue template suggests:

 - Laravel: v#.#.#
 - Voyager: v#.#.#

As the error says GD driver doesn't support SVG files, it's not a bug and it doesn't depend from Voyager.
You can try to change your driver to imagick, if you have it installed, in config/image.php.

http://image.intervention.io/getting_started/configuration

php artisan vendor:publish --provider="Intervention\Image\ImageServiceProviderLaravelRecent"

I also get this issue with Voyager Settings replacing the admin loader with svg file.

  • Laravel: v6.4.0
  • Voyager: v1.3.0

SVG doesn't need to be resized or supported by Intervention. Even with Imagick it throws error:
https://github.com/Intervention/image/issues/52

Problem is because there's no validation of mime types in:
Http/Controllers/ContentTypes/Image.php

I can't find any Intervention validation method but this is how they're doing it

// get mime type of file
$mime = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $path);

// define core
switch (strtolower($mime)) {
    case 'image/png':
    case 'image/x-png':
    case 'image/jpg':
    case 'image/jpeg':
    case 'image/pjpeg':
    case 'image/gif':
    case 'image/webp':
    case 'image/x-webp':
}

@MrCrayon I've added a check for the mime type before resizing the image and allows SVG to be uploaded.
Could you please check I've committed it correctly.
https://github.com/the-control-group/voyager/commit/ea9c21577d885a9afdbfb15416ac92be627779c9

Was this page helpful?
0 / 5 - 0 ratings