Moodle

Scalable Vector Graphics (SVG) files in Moodle are not correctly displayed in many Browsers

Details

  • Type: Improvement Improvement
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 1.6.2
  • Fix Version/s: 1.6.3, 1.7
  • Component/s: Resource
  • Labels:
    None
  • Environment:
    Any

Description

Applies to Web browsers (Firefox, Opera) that natively display SVG and require correct MIME type to be served from Moodle.
Internet Explorer + Adobe SVG Plugin view does not have a problem as it renders SVG base on the .svg extension alone.

Problem can be simply resolved by adding the following lines to function get_mimetypes_array() in /lib/filelib.php

i.e.

'svg' => array ('type'=>'image/svg+xml', 'icon'=>'image.gif'),
'svgz' => array ('type'=>'image/svg+xml', 'icon'=>'image.gif'),

Issue Links

Activity

Hide
Petr Škoda (skodak) added a comment -

fixed in cvs, thanks for the report and patch!

Show
Petr Škoda (skodak) added a comment - fixed in cvs, thanks for the report and patch!
Hide
Stephen Bourget added a comment -

This fix seems to work only in the case wher you add the file as a resource using "Link to a file or website". If you add the svg using any other method (to a forum post, as an image on a resource, etc) it seems to fail.

The built-in HTML Editor rejects svg files as "not an image"

This can be fixed by changing line 63 of lib\editor\htmlarea\coursefiles.php
From:

if(params.itype.indexOf("image/gif") == -1 && params.itype.indexOf("image/jpeg") == -1 && params.itype.indexOf("image/png") == -1)

To:

if(params.itype.indexOf("image/gif") == -1 && params.itype.indexOf("image/jpeg") == -1 && params.itype.indexOf("image/png") == -1 && params.itype.indexOf("image/svg") == -1)

However even if the svg is added to Moodle using HTML.

<img border="1" style="width: 135px; height: 102px;" title="svg?" alt="svg?" src="http://localhost/Tectonic_plates.svg" />

or

<img hspace="0" border="0" title="SVG" alt="SVG" src="http://localhost/moodle17/file.php/2/Tectonic_plates.svg" style="width: 102px; height: 102px;" />

The image will fail to be displayed.

Thoughts?

Show
Stephen Bourget added a comment - This fix seems to work only in the case wher you add the file as a resource using "Link to a file or website". If you add the svg using any other method (to a forum post, as an image on a resource, etc) it seems to fail. The built-in HTML Editor rejects svg files as "not an image" This can be fixed by changing line 63 of lib\editor\htmlarea\coursefiles.php From: if(params.itype.indexOf("image/gif") == -1 && params.itype.indexOf("image/jpeg") == -1 && params.itype.indexOf("image/png") == -1) To: if(params.itype.indexOf("image/gif") == -1 && params.itype.indexOf("image/jpeg") == -1 && params.itype.indexOf("image/png") == -1 && params.itype.indexOf("image/svg") == -1) However even if the svg is added to Moodle using HTML. <img border="1" style="width: 135px; height: 102px;" title="svg?" alt="svg?" src="http://localhost/Tectonic_plates.svg" /> or <img hspace="0" border="0" title="SVG" alt="SVG" src="http://localhost/moodle17/file.php/2/Tectonic_plates.svg" style="width: 102px; height: 102px;" /> The image will fail to be displayed. Thoughts?
Hide
Stephen Bourget added a comment -

I was trying to insert the svg file incorrectly.

The fix works on Moodle 1.7beta

Closing

Show
Stephen Bourget added a comment - I was trying to insert the svg file incorrectly. The fix works on Moodle 1.7beta Closing

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: