Scalable vector graphics is a commonly used file format for providing a geometrical description of an image using basic objects such as labels, circles, lines, curves and polygons. An image can be reduced or enlarged to an arbitrary size, and will not suffer image data loss, nor will it become pixelated. SVG makes an excellent format for artwork, diagrams and drawings. SVG images are defined in XML text files. This means that they can be searched, indexed, scripted and, compressed. Since they are XML files, SVG images can be edited with any text editor, but SVG-based drawing programs are also available.
However, the rendering engine used by wiki is not perfect, and may cause the image to be shown incorrectly, or differently from how it is displayed in your vector editor of choice. This page enables authors experiencing problems with SVG graphics to obtain some help in getting their images into wiki the way they intend.
Things we can help with
Using SVG appropriately
What you see is not what you get
Testing for problems
The following SVG checkers may help you to detect SVG problems before you upload:
flowRoot does not appear
If black box appear, read c:User:JoKalliauer/RepairFlowRoot how to solve this issue, but do not remove those objects since they might contain text. The workarounds that one can employ are either not to use flowed text (by using the text tool without creating a text field), or convert the text to normal text (by Text-editor or sed-comand, or with Inkscape-GUI or with a Inkscape-batch), but to stroke the text using "object to path", since path-text is not recomended and increases file-size.
Due to copyright restrictions, MediaWiki cannot use proprietary fonts that are commonly found on several proprietary operating systems. Fonts such as Geneva require licensing fees to distribute. rsvg will not be able to locate such fonts, and the text will fail to appear in the rendered image. There are three solutions to this issue:
For ease of subsequent editing and significantly smaller file sizes, substituting the font with an available font is recommended. Many common fonts have non-proprietary alternatives that are similar in typographical style, resulting in minimal disruption to existing images during substitution. For a list of fonts available in Wikipedia, see available fonts on Meta.
Fonts that are available on Wikimedia servers may or may not be available on a visitor's machine. If the placement or appearance of text in the image is important and there is uncertainty about which fonts are installed on a visitor's machine, then converting text into path information may be necessary.
bad letter-alignment on small font-size
Librsvg calculates the letter-distances inaccurantly for font-sizes of 20px and below.
For a text like
<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg"> <text x="20" y="30" font-size="5px">exampletext</text> </svg>
you can replace it with:
<svg viewBox="0 0 1000 1000" xmlns="http://www.w3.org/2000/svg"> <text x="200" y="300" font-size="50px">exampletext</text> </svg>
<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg"> <g transform="scale(0.1)"><text x="200" y="300" font-size="50px">exampletext</text></g> </svg>
Missing embedded JPEG images
When a raster graphic is embedded in an SVG it is encoded into base64 data. That data is then assigned a MIME type in the <image> element. In the case of an embedded JPEG, the MIME type is "image/jpeg". Older versions of Inkscape (and possibly other editors) assigned the MIME type "image/jpg". While Inkscape and most web browsers will display such an SVG image just fine, the MediaWiki software that rasterizes the SVG file will have trouble with it. Not recognizing the MIME type "image/jpg" there will simply be an empty space where the image is supposed to be. The fix is to open the SVG file in a text editor, find the <image> element, locate "image/jpg", change it to "image/jpeg" and re-save. At right is an example of this problem. The Commons SVG Checker looks for this problem; see Commons:Commons:Commons SVG Checker/KnownBugs#Checks for details.
Though Web browsers cope with image tags without width and height specified, librsvg ignores such images.
If circle-segmentes are distorted it is often due to reduced spaces between arc-to-flags, see phab:T217990 for details.
Further issues can be found at c:Librsvg_bugs or at Commons:Commons:Commons SVG Checker/KnownBugs, and examples can be found at c:Category:Pictures_demonstrating_a_librsvg_bug. However most issues (for files <1MB) can be fixed using https://svgworkaroundbot.toolforge.org/ (enable "run svgcleaner" and enable "run scour" before clicking convert), for a more detailed list check c:User:SVGWorkaroundBot.
MediaWiki (the software from which Wikipedia is run) uses the librsvg-library to rasterize all of its svg files. The version of the rsvg program that is installed on wiki does not always correctly raster the Inkscape or OpenOffice.org SVG files, and does not recognize some formats in text-editor SVG files. The file manager GNOME Files or c:Commons:Commons_SVG_Checker relies on librsvg, so it can be used to check the quality before a SVG is uploaded.
Rendering Inkscape files
There is a simple work-around for the scarcities of librsvg. The operation "Stroke to Path", to be found under Menu>Path in Inkscape or via Ctrl+Alt+C, can be applied to all of the objects that are not rendered correctly. To keep the SVGs editable, this should only be done to the files intended for upload, and these files can be deleted afterwards.
As of February 2014, the objects that must be modified to render correctly by librsvg include:
Rendering OpenOffice.org SVG files
OpenOffice.org SVG files may require manual modification before being uploaded to Wikipedia. To achieve this:
NB: Vector graphics line widths may also need to be set explicitly in OpenOffice.org Draw.
SVG code replacement guide (executing replace all using Nedit regular expressions)
This SVG export procedure has been tested using OO 2.3.0 and OO 3.2.1 with a simple .odg candidate.
Rendering text-editor SVG files
SVG files created from scratch in a text editor may make use of any valid SVG syntax, so long as your browser supports the given version of the SVG specification. On Wikipedia however, SVGs are interpreted by the librsvg-library to create PNG previews at different image sizes. That library only recognizes a subset of all valid SVG syntax, and may render your SVG without many features. In order to bypass these deficiencies in the library, there are certain parameters that need to be formatted in specific ways or be assigned a workaround value in order for librsvg to accurately render views of your SVG file.
<mask> parameter maskUnits="userSpaceOnUse"
The librsvg-library does not interpret the value of
The librsvg-library does not accept a
In Wikimedia projects, <use xlink:href="#myobjectname" transform="translate(10 10)" /> will render properly if you have specified xmlns:xlink="http://www.w3.org/1999/xlink". Be aware that href= by itself will not work on Wikimedia projects even though it might render properly if directly read by your browser.
If you have a tricky SVG file with a problem not described, or can't quite figure out what the previous section was talking about, you can simply ask for assistance by posting a quick note hereafter that outlines the problem, as well as providing links to the files that are exhibiting these problems. Don't forget to sign your name with four tilde symbols (~~~~) and an editor will attempt to reply here to help!
When you are happy that a request has been fulfilled, just leave a note so that the request can be archived later, as needed.
An alternative source of help is Commons:Graphics village pump.
1: April 2008 – July 2008
2: July 2008 – February 2009
3: February 2009 – May 2010
4: May 2010 – November 2010
5: February 2011 – January 2013
6: January 2013 – September 2017
7: October 2017 – February 2020
8: February 2020 – present
Hi. See commons:Commons:Graphics village pump#WTF is wrong with File:Selenium logo.svg (just trying to get visibility, as that page is not very active) -- something is totally wrong with the rendering of this SVG and I would like to know if anyone can fix it. DemonDays64 (talk) 01:10, 27 September 2021 (UTC)
Generating SVGs of symbols from fonts
Could someone point me in the right direction? I'd like to create SVGs of symbols on a transparent background, converting the font I have to graphics so they display properly. Thanks. — kwami (talk) 11:35, 27 September 2021 (UTC)
- Kwamikagami, the simplest way to do this would be by installing the font to your system, typing using it in Inkscape, converting to paths and exporting as an SVG. If you want to do a batch of these it's a bit harder. You could try installing the open-source font editor FontForge, and following this guide on how to export SVGs en masse by the command line from Stack Overflow. I'm sure there are other ways that maybe people can give input on. — Berrely • Talk∕Contribs 18:19, 27 September 2021 (UTC)
- That should give me enough to work with, thanks. I'd tried 'converting to lines', but it had no effect. I'll try again to see what I did wrong. — kwami (talk) 18:36, 27 September 2021 (UTC)
Possible Rsvg bug causing gaps in mask where two shapes abut
Hi Rsvg experts,
I used two bow-tie shapes filled with a linear gradient (the second rotated 90 degrees) in a mask to fade out the edges of the right-hand figure. Some pixels are not painted where the shapes meet each other at the diagonals, giving a large faint white "X". It's much less apparent when opening the SVG in a browser. Can this be considered a bug in the thumbnail renderer?
Can someone suggest a workaround to get this fade-out effect, perhaps using SVG filters?
- @Cmglee: Reading https://github.com/RazrFalcon/resvg/issues/234 I would consider hairline-cracks as a malformed SVG, since most libaries render/antialise it wrong. It is listed at c:Librsvg_bugs#Hairline_cracks.
- The only way to workaround this render-issue is to draw overlapping. — Johannes Kalliauer - contrib. 12:01, 29 September 2021 (UTC)
- For filters check the discussion at https://gitlab.com/inkscape/inkscape/-/issues/928 — Johannes Kalliauer - contrib. 12:05, 29 September 2021 (UTC)
- Thanks for bringing hairline cracks to my attention, @JoKalliauer:. Shame there's no elegant solution. I've replaced the mask with the SVG filter below. Cheers, cmɢʟee⎆τaʟκ 22:45, 29 September 2021 (UTC)
<filter id="filter_fade"> <feMorphology operator="erode" radius="2"/> <feGaussianBlur stdDeviation="1"/> <feComposite operator="in" in="SourceGraphic"/> </filter>
Not rendering SVG
Can someone perhaps take a look at de:File:BaumNeu3.svg. I you remove the title tag and replace the first SVG tag with the width, height and viewbox with just <svg> it works for some reason but doesn't display the entire file I think.Jonteemil (talk) 14:39, 8 October 2021 (UTC)