Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I've added the SVG file extension for image uploads via admin/structure/types/manage/image/fields/gallery_image, as you see below:

enter image description here

But when I go to upload an image, I'm still not allowed to upload SVG.

enter image description here

I definitely pressed "Save" in the admin page, and I cleared the cache, and I even see the settings as I wanted them in the database, when I inspect the field_config_instance table. There must be some other table or cache that's not updating. Any idea?

share|improve this question

4 Answers 4

The Image widget internally allows (and silently enforces post Drupal 6) the use of only the png, gif, jpg and/or jpeg extensions. So, while you can remove an extension from a field, eg, I have removed gif from most of my implementations to avoid anything animated, you can't add any to this list. I would imagine this is because it in itself displays the image after being uploaded and didn't want to break any displays in older IE browsers in the actual form (plus, who knows how image styles would work on them as well :)

share|improve this answer
    
Good answer, but what a pity. –  Joe Corneli Dec 28 '13 at 23:32
1  
A discussion on d.o is here: drupal.org/node/1014816 –  Joe Corneli Dec 28 '13 at 23:36

You can simply use a file field and implement hook_field_formatter_info_alter in your custom module to enable the "Image" formatter also for file fields. Then you can easily ouput for uploaded SVG as embedded image.

/**
 * Implements hook_field_formatter_info_alter().
 */
function MODULNAME_field_formatter_info_alter(&$info) {
  $info['image']['field types'][] = 'file';
}
share|improve this answer

As noted, there's no easy way to simply allow Drupal's core Image module to accept SVG. Instead you can use the contributed module SVG Embed (grudgingly chosen over a filefield for SVG in this discussion) or this sandbox (not officially released) SVG module.

UPDATE: I now recommend svgimg also in Sandbox but likely being released soon. Using it in production, and very happy.

share|improve this answer

There is also another way around it--using the Media module. Once this is installed, the SVG format can be added at admin/config/media/file-types, under image.

If I'm not mistaken, Drupal still doesn't allow SVGs by default due to backwards compatibility concerns (primarily IE8 and below). I've been placing SVGs for some time on projects, though, and have yet to hear a complaint.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.