Displaying SVG files in Moodle

Displaying SVG files in Moodle

by Geoffrey Rowland -
Number of replies: 4
Picture of Plugin developers
Hi folks

I have been trying to display .svg files by uploading them to the Files folder of a course, and then linking to them as standard Moodle resources (Add a resource... >> Link to a file or website etc)

These display nicely with Internet Explorer (using the Adobe SVG Viewer plug-in), but not with Firefox or Opera (an Open with.../Download to... dialogue appears instead) even though these natively render SVG. I presume this is because Opera and Firefox, being standards-compliant, need to have the appropriate SVG MIME type passed to them from the webserver, whereas Internet Explorer renders the files as SVG based on their .svg extension alone.

See e.g. http://wiki.svg.org/MIME_Type

However, the SVG MIME types are correctly set up for the webserver, and indeed .svg files placed in non-Moodle directories on the webserver display correctly in all three browsers.

I'm guessing the problem arises because resources in the Files folder are located in the /moodledata folder outside the web root, so the appropriate SVG MIME types are not sent.

Is this the problem, and can anyone suggest a solution? I realise this is not exactly a 'show stopper', but it would still be nice if things worked well with Firefox & Opera.

I have attached a sample SVG file, in case anyone would like to experiment.

Cheers

Geoff
Attachment butterfly.svg
Average of ratings: -
In reply to Geoffrey Rowland

Re: Displaying SVG files in Moodle

by Geoffrey Rowland -
Picture of Plugin developers
Hi again

As is usual with Moodle cool, once I worked out where to look the solution was simple.

Just added the following lines to function get_mimetypes_array() in /lib/filelib.php.

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

Adding appropriate MIME types to filelib.php should work for similar problems with direct viewing of 'unusual' file types.
In reply to Geoffrey Rowland

Re: Displaying SVG files in Moodle

by Geoffrey Rowland -
Picture of Plugin developers
Thanks to Petr Škoda and the Moodle Bug Tracker, this is now fixed for Moodle 1.6.2+ CVS, and forthcoming 1.6.3 and 1.7.

MDL-6878
In reply to Geoffrey Rowland

Re: Displaying SVG files in Moodle

by Ger Tielemans -
Are all the modern webbrowsers supporting .svg?
In reply to Ger Tielemans

Re: Displaying SVG files in Moodle

by Geoffrey Rowland -
Picture of Plugin developers
Ger

SVG is supported in:
Firefox 1.5 or later (built in)
Opera 8 and later (built-in)
Amaya (built-in)
Konqueror (with KSVG module, soon KSVG2 to be built-in)
Safari (with Adobe SVG Viewer plug-in, soon to be built-in)
Internet Explorer (with Adobe SVG Viewer plug-in)

As ever, with different browsers there are varying degrees of support, but this has improved with the latest e.g. Firefox 2 and Opera 9.

Adobe have announced that it will discontinue support for Adobe SVG Viewer on January 1, 2008, - presumably as they expect that SVG will be natively supported by most browsers (including Internet Explorer?) in the near future. It may also be that, since their acquisition of Macromedia, they are more interested in encouraging folks to 'stick with' Flash rather than the open-standard, XML-based SVG format.

A good overview of SVG is given in

and more detail on browser support
Regards

Geoff