Wikipedia:SVG help

__NEWSECTIONLINK__ {| style="clear:both; background:white;"
 * width="50%" style="padding:1em; border:1px solid #A3B1BF; background-color:#E6F2FF" valign="top"|
 * width="50%" style="padding:1em; border:1px solid #A3B1BF; background-color:#E6F2FF" valign="top"|

SVG help

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
 * style="vertical-align:top;padding:1em; border:1px solid #A3B1BF; background-color:#E6F2FF" |

Understanding SVG


 * Questions about the SVG format

Using SVG appropriately


 * When to (or not to) use SVG

What you see is not what you get


 * Missing objects from files
 * Random filled boxes in the image
 * Images that are the wrong size
 * Font inconsistencies
 * Other weird and wonderful bugs

Something new


 * Questions that you can't find a better place for




 * colspan="2" style="border:1px solid #B1A3BF; padding:1em 1em 1em 1em; background-color:#F2E6FF" |

General suggestions
The following is a list of common vector editors and suggested settings for compatibility. The user guide of your chosen program may also be valuable in troubleshooting.

Browsers
Most modern browsers can render SVGs in view-only mode. It may be convenient to set a browser as the default SVG viewer, but you can also paste the file path into the address bar. Please note that even if your browser renders an SVG correctly, it may render differently on Wikipedia.

Text editors
SVG documents are text files, and can be edited like any other text file. Specifically, SVGs are XML documents, which have special support in many text editors. One potential disadvantage to editing SVGs by hand is that previewing your changes is more cumbersome. A rudimentary solution would be to open the SVG file in a browser while working on it, and manually refreshing the document to see the result of changes.

Inkscape
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, 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:
 * Lines with arrow heads (the arrows need to be converted)
 * Text, that has been transformed, e.g. "Text on Path"
 * Compound objects created with the binary path tools (union, intersect etc.)

OpenOffice.org
OpenOffice.org SVG files may require manual modification before being uploaded to Wikipedia. To achieve this:
 * Change all fonts to Wikipedia supported fonts as mentioned before. (E.g. change "Sans embedded" to "DejaVu Sans".)
 * Add "px" to all font-size references. (E.g. change "font-size:100" to "font-size:100px".)
 * Remove all additional x coordinate references in  elements. (E.g. change   to  .)
 * [Not required for OO 2.3.0] Explicitly colour all text (e.g. black) by replacing relevant "stroke:none;fill:none" instances with "stroke:none;fill:rgb(0,0,0)" (note that simply explicitly colouring text black in OpenOffice 3.2.1 does not appear to work).

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.

Microsoft Powerpoint
It is easiest to save entire slides from Powerpoint as svg rather than saving multiselected objects with right click / save as picture, because for entire slides the boundaries will be cropped to the size of the slide and the background will be set to white. To save slides as svg, use file / save as / browse / save as type --> svg.

If your slide has text, open the exported svg into Notepad and replace all the existing font-family specifications with. This specification will make Wikimedia render SVG fonts similarly to how browsers render Wikipedia fonts.

Text can also get chopped up on export, which causes rendering and localization bugs. To fix this, search for all tags and make sure the tag isn't embedded in another text tag that's on the same line of text. Most embedded text tags can simply be deleted; however, but if content needs to be subscripted or subscripted, then replace the text tag with a  specifiction. For subscripts, use. For superscripts, use.

Use text over paths
Converting text in an SVG file into paths (shapes) increases file size, prevents localization/accessibility features, and complicates edits/modifications down the line. It is therefore generally disfavored, with some exceptions, such as text-based logos. The Wikimedia text renderer can introduce bugs as its fonts may differ from browser fonts or SVG editor fonts, but following the guidance below should minimize these errors.

font-family property
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:


 * One can substitute a font that is available on Wikipedia. This approach facilitates editability.
 * One can specify a generic  such as "sans-serif", "serif", or "monospace", but this can lead to inconsistent rendering. It is better to specify a font available on Wikipedia (such as Liberation Sans) with fallback fonts such as: , in which you define a font-list with similar fonts that at least contain one font for each Operating System such as Wikimedia (e.g. Liberation Sans), Windows (e.g. Arial), Linux (e.g. Liberation Sans), Mac (e.g. Helvetica).
 * Since local rendering should be as close as possible to Wikipedia, it should use locally the same font as it will have on Wikipedia, if available. Therefore always define a Wikimedia-font first. Also, Wikimedia has synonyms for substituting fonts, such as "Arial" for "Liberation Sans"; therefore  will be rendered by "Liberation Sans" and not (as expected) by "DejaVu Sans". (This is because "Liberation Sans" has the same letter size as "Arial" [metric-compatible], so it is less likely to mess up the text flow.)
 * Group the text, create a copy, and convert the copy to paths. Then either:
 * move the original, editable non-path text into a separate editable text layer that you make transparent (warning: this might be removed by SVG optimizers), or
 * move the original, editable non-path text outside the visible area (example: File:Essigsäuresynthesen.svg).

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.

Wikimedia has default fonts, and will use Liberation Serif for Times New Roman and Liberation Sans for Arial. For further fallbacks see c:Help:SVG.

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.

font-size property
Fonts should be sized so that they look good as thumbnails on wikipedia pages and so they are easy to view on smartphones. Smartphones are how most people access wikipedia. Thumbnails are how most other people see images, as very few people click images and zoom them in to see them. Avoid using or creating images with fonts that are too small to be legible in thumbnail or smartphone views.

The font size that appears in a thumbnail is a combination of svg width, thumbnail width, and font size. To match wikipedia font size as a thumbnail, use font-size = (63/(your upright value))*((your svg width)/1000). For instance, if the thumbnail will be scaled up to thumb upright=1.35 and your image has svg width of 960, set font-size in the svg to (63/1.35)*(960/1000) = 44.8.

Background colors
Transparent backgrounds are fine, but do not think your image will always be displayed on a light or white background. The wikipedia smartphone app, for instance, renders images on a black background, so if you show black text on a transparent background it will be invisible.

Testing for problems
The following SVG checkers may help you to detect SVG problems before you upload:
 * WMF Labs SVG check
 * Commons SVG Checker
 * w3.org validator

None of these checkers are foolproof, so it's wise to validate images. You can preliminarily validate images by uploading them to the shared, temporary-use location, though other users may overwrite your image at any time.

To force refresh images in your browser use Ctrl+F5 (Shift-Reload on Mac), so that you see the latest upload and not cached image copies (this is necessary even on wikimedia upload pages).

Rendering SVG files
On Wikipedia SVGs are interpreted by the librsvg-library to create PNG previews at different image sizes (to rasterize them). 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. Some issues are enumerated below, but be sure to test your SVG files before and after uploading them.

&lt;mask&gt; parameter maskUnits="userSpaceOnUse"
The librsvg-library does not interpret the value of  for the parameter   correctly. To bypass this issue, replace  with , and the SVG mask will render properly on Wikipedia.

parameter stroke-dasharray
The librsvg-library does not accept a   parameter with values separated by spaces. Replace all spaces with commas to bypass this issue: Example: replace  with

Use xlink:href=, not  href=  alone, in  statements
In Wikimedia projects,  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.

CSS selectors or identifiers must start with a letter or hyphen
http://w3.org/TR/css-syntax-3 states, "Property names and at-rule names are always identifiers, which have to start with a letter or a hyphen..."

Misaligned text
The latest thumbnail-image-maker (named rsvg) unfortunately has a bug which misaligns centre- or right-aligned  tags containing   tags on the same line. While developers work on a solution, here are some remedies in decreasing usefulness:
 * Left-align affected  tags with
 * Specify either the  or   attribute for affected   tags
 * If using multiple  tags on a line for:
 * word and character spacing, use:
 * (non-breaking space),  (thin space) and/or   (hair space) characters
 * the  attribute
 * a monospaced font such as  (last resort)
 * subscripts or superscripts, use Unicode subscripts and superscripts
 * bolding or italicizing variables etc in mathematics, use Unicode Mathematical Alphanumeric Symbols
 * Merge affected  tags, even unitalicising variables etc if above methods fail
 * Convert text into shapes (last resort, as the text can no longer be amended, copied or read by screen-readers)

flowRoot does not appear


If a black box appears, 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-command, or with Inkscape-GUI or with a Inkscape-batch), but to stroke the text using "object to path", since path-text is not recommended and increases file-size.

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 &lt;image&gt; 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 &lt;image&gt; 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 for details.

Though Web browsers cope with image tags without width and height specified, librsvg ignores such images.

Further issues
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.


 * }
 * }

Assistance
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.

= Current requests =

Create a new request

Path elements don't appear, except directly in Chrome and Safari (not in Firefox)
The file description page, and Wikipedia renderings, do not render 14 differently-colored trapezoidal paths that should be visible in front of the 14 yellow rectangles. Clicking through to the renderings in Chrome and Safari, the trapezoids show up as they should. However, the trapezoids do not show up using Firefox. ( ~ scratches head ~ )

Adding  did not help. Could the difference between relative and absolute coordinates possibly be the problem? * Yellow rectangles:

Trapezoids:
 * etc etc
 * etc etc
 * etc etc

Update 1: the problem is definitely in the trapezoids group itself, as they are not showing up at after I purposely removed the yellow-rectangles group.

Update 2: Notice how, at, some of the "File history" thumbnails show the colored trapezoids, but the main display shows an old version.

(Yes, I've cleared my browser cache, many times.)

Any help would be appreciated! — RCraig09 (talk) 17:45, 17 June 2024 (UTC)
 * This is the code:  In Firefox 127.0 they are there, but extremely narrow - they have the appearance of vertical lines of varying height, the thickness of the line corresponds with the very narrow stroke-width: one-tenth of a pixel, when your canvas is 1200px wide, is barely perceptible. At that sort of scale, the black is largely lost as the colour of the adjacent pixels swamps these lines. -- Red rose64 &#x1f339; (talk) 07:59, 18 June 2024 (UTC)
 * you have a spurious extra comma on every  attribute in that block. Change   to   and similarly for all of the others. -- Red rose64 &#x1f339; (talk) 08:03, 18 June 2024 (UTC)


 * D'oh! I have committed a rookie error. Many thanks, User:Redrose64. — RCraig09 (talk) 14:22, 18 June 2024 (UTC)
 * Interesting. Ordinarily, commas and spaces are equivalent in path d attributes but here it makes a difference. cm&#610;&#671;ee&#9094;&#964;a&#671;&#954; 11:18, 19 June 2024 (UTC)

Text misaligned (not previous bug)
Would anyone know why the letter W on this cake number diagram is not centred, as it appears on http://svgcheck.toolforge.org and popular browsers?

Thanks, cm&#610;&#671;ee&#9094;&#964;a&#671;&#954; 00:41, 6 July 2024 (UTC)

c:File:UK Election 2043.svg
It would be appreciated if anyone could fix this file. Adding  didn't help. Jonteemil (talk) 20:27, 17 July 2024 (UTC)
 * Per c:Help:SVG, the SVG file needs to begin with the XML prolog and you should also specify the   attribute on the  tag.
 * But what's all this  stuff that appears in most elements? It's not an attribute that I recognise. I certainly can't find it in the SVG 1.1 spec. -- Red rose64 &#x1f339; (talk) 23:53, 17 July 2024 (UTC)
 * I'm not the original uploader, I just tried to fix an erroneous file. If you could fix it it'd be good, but not for me personally that is. Questions about the file I can thus not answer. Jonteemil (talk) 23:57, 17 July 2024 (UTC)
 * I can't fix it if I don't know what  is supposed to do. Have you informed the original uploader about the problems? -- Red rose64 &#x1f339; (talk) 23:59, 17 July 2024 (UTC)
 * Here's my assessment of the content of the file. It has:
 * one  element, which has three valid attributes and six invalid attributes
 * one  element, which has one invalid attribute
 * 600+  elements, each of which have two valid attributes and five invalid attributes
 * That's more than three thousand invalid attributes in the entire file. I don't think that it's easily fixable. Should I send it to c:COM:FFD? -- Red rose64 &#x1f339; (talk) 19:03, 19 July 2024 (UTC)
 * Do it. Jonteemil (talk) 19:01, 20 July 2024 (UTC)
 * Nvm, it qualifies for speedy deletion so I tagged it for that instead. Jonteemil (talk) 19:03, 20 July 2024 (UTC)
 * Voting to close as I get a blank screen on Firefox, Chrome and Edge. Even its name (2043) sounds dubious. cm&#610;&#671;ee&#9094;&#964;a&#671;&#954; 01:15, 19 July 2024 (UTC)