When I run 'refresh media entity thumbnails' I see:

An AJAX HTTP error occurred.
HTTP Result Code: 200
Debugging information follows.
Path: /batch?id=9207&op=do_nojs&op=do
StatusText: parsererror
ResponseText: TypeError: Argument 1 passed to SVG\Reading\SVGReader::parseXML() must be an instance of SimpleXMLElement, bool given, called in /Users/REDACTED/REDACTED/REDACTED/vendor/meyfa/php-svg/src/Reading/SVGReader.php on line 104 in SVG\Reading\SVGReader->parseXML() (line 115 of /Users/REDACTED/REDACTED/REDACTED/vendor/meyfa/php-svg/src/Reading/SVGReader.php).

I'm guessing some of my SVG files are missing the XML version tag maybe? Not sure. I'm not going to be able to convince the client to fix their files so is there something we can do in the module to fix this? I can't see anything in the module about allowed mime types?

Comments

darren.fisher created an issue. See original summary.

drubb’s picture

Hi,

thanks for reporting this issue. Not sure how to solve this in the module's code, because the error is thrown by the underlying php library (composer package), meyfa/php-svg. However, it's not a missing XML version tag, that should not cause any issues as you can see in this example: https://github.com/meyfa/php-svg/wiki/Reading-SVGs

Converting the SVG to a raster image is the first task in the module's media thumbnail plugin (/src/Plugin/MediaThumbnail/MediaThumbnailSVG):

 $image = SVG::fromFile($sourceUri);
    if (!$image) {
      $this->logger->warning($this->t('Media entity source file (svg) not found.'));
      return NULL;
    }

SVG is the mentioned library class. BTW, in this plugin file you'll also find the mime type constraint, as annotation, it's "image/svg+xml".

If there's only a handful of svgs to be converted, try uploading them one by one in the media library, thumbnails will be generated on save. That might lead you to a file throwing this error. Then we can take a look at the file contents.

drubb’s picture

There's now a new dev release of this module, implementing a rasterizer fallback:

GraphicsMagick -> ImageMagick -> PHP GD

For GraphicsMagick and ImageMagick it's using the CLI tools directly, no php extensions required. There's some information on the status page about the rasterizer in use.

Please try it out. If it doesn't solve your issue, I'll need some more details:

- when does it happen (immediately or after processing x% of the files)
- are there errors when you edit and save the media entities?
- are there svgs that are completely empty?

barry_fisher’s picture

Status: Active » Closed (outdated)

I'm working with Darren on this issue and we've progressed since this issue was created - especially given your latest dev release. Therefore, I'll close this on Darren's behalf.

Thanks @drubb!