Wikipedia:SVG help
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 Understanding SVG
Using SVG appropriately
What you see is not what you get
Something new
| ||||||
General suggestions[edit]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[edit]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[edit]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[edit]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:
OpenOffice.org[edit]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)[edit]
This SVG export procedure has been tested using OO 2.3.0 and OO 3.2.1 with a simple .odg candidate. Microsoft Powerpoint[edit]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 Text can also get chopped up on export, which causes rendering and localization bugs. To fix this, search for all Microsoft Visio[edit]Generating SVG charts from Microsoft Excel[edit]![]() Warming stripes (five examples compared) Warming stripes bar chart Bar chart (vertical) Pie chart Line charts Scatterplot I've uploaded .xlsx (Microsoft Excel) spreadsheets that automatically generate XML code for charts in SVG format. You simply paste or enter your data into the spreadsheet, and specify image dimensions, number of grid lines, font sizes, etc. The spreadsheet instantly and automatically generates a column of XML code that you simply copy and paste into a text editor and save as an ".svg" file. The spreadsheets produce lean SVG code, avoiding the "extra stuff" that Inkscape inserts. They should save you time in creating SVG charts. Feedback and suggestions on my talk page are welcome. RCraig09 (talk) 23:41, 19 February 2021 (UTC) Click HOW TO for detailed explanation.
Example SVG files: Category:SVG diagrams created with spreadsheet.
Text guidance[edit]Use text over paths[edit]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[edit]![]() 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. 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#fallback. 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[edit]![]() font-size="35" (or larger) appears to avoid this problem, depending on the pixel size of your graphic.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[edit]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[edit]The following SVG checkers may help you to detect SVG problems before you upload: 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 Test.svg, 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[edit]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. <mask> parameter maskUnits="userSpaceOnUse"[edit]The librsvg-library does not interpret the value of parameter stroke-dasharray[edit]The librsvg-library does not accept a Use xlink:href=, not href= alone, in [edit] |
Assistance
[edit]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
[edit]
This page has archives. Sections older than 30 days may be automatically archived by Lowercase sigmabot III when more than 4 sections are present. |
Text misaligned (not previous bug)
[edit]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ɢʟee⎆τaʟκ 00:41, 6 July 2024 (UTC)
- @Cmglee: Similar to Commons:Commons:Graphics_village_pump#Issues_with_E-road_shields_(Tabliczka_set) it's the non-uniform scaling (in this case
transform="scale(1.732,1)"
), which somehow makes the SVG renderer mess up the position of the text. TilmannR (talk) 19:01, 30 July 2024 (UTC)- Thanks very much, @TilmannR: Seems the new rsvg has caused a new regression.
- @Philvoids: has reported an issue with another file.
- @JoKalliauer:@Aklapper:@Snaevar: are the Mediawiki people aware of this issue?
- Cheers, cmɢʟee⎆τaʟκ 00:40, 31 July 2024 (UTC)
- P.S. From commons:Commons:Graphics_village_pump#Issues_with_E-road_shields_(Tabliczka_set), I gather there is no good workaround other than not non-uniformly scale text. Is anyone aware of one? cmɢʟee⎆τaʟκ 00:48, 31 July 2024 (UTC)
It would be appreciated if anyone could fix this file. Adding xmlns="http://www.w3.org/2000/svg"
didn't help. Jonteemil (talk) 20:27, 17 July 2024 (UTC)
- @Jonteemil: Per c:Help:SVG#Document declaration, the SVG file needs to begin with the XML prolog (
<?xml version="1.0" encoding="UTF-8"?>
) and you should also specify theversion="1.1"
attribute on the<svg>
tag. - But what's all this
candidates=
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. --Redrose64 🌹 (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
candidates=
is supposed to do. Have you informed the original uploader about the problems? --Redrose64 🌹 (talk) 23:59, 17 July 2024 (UTC) - Here's my assessment of the content of the file. It has:
- one
<svg>...</svg>
element, which has three valid attributes (xmlns=
style=
viewBox=
) and six invalid attributes (tossup-candidate=
candidates=
auto-border-stroke-width-limit=
auto-border-stroke-width=
title=
type=
) - one
<g>...</g>
element, which has one invalid attribute (map-type=
) - 600+
<path>...</path>
elements, each of which have two valid attributes (style=
d=
) and five invalid attributes (candidates=
value=
long-name=
short-name=
region=
)
- one
- 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? --Redrose64 🌹 (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)
- Do it. Jonteemil (talk) 19:01, 20 July 2024 (UTC)
- I can't fix it if I don't know what
- 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)
- Voting to close as I get a blank screen on Firefox, Chrome and Edge. Even its name (2043) sounds dubious. cmɢʟee⎆τaʟκ 01:15, 19 July 2024 (UTC)
![](http://upload.wikimedia.org/wikipedia/en/thumb/f/fb/Yes_check.svg/20px-Yes_check.svg.png)
SVG Thumbnail Color Rendering Issues
[edit]- c:File:Sadri (Nagpuria) language distribution map.svg
- c:File:Kudmali language region.svg
- c:File:Bhumij language.svg
I've made these choropleth maps using Inkscape, using existing SVG maps from commons. But recently, Assam region showing up in black on the thumbnail (jpg/png) image, instead of their correct colors from the original SVG files (this problem started about 3-4 months ago). Could someone please fix this issue? ~ MaxA-Matrix 🗨 05:08, 24 July 2024 (UTC)
- @MaxA-Matrix: I see what you mean. But these images are far too large and complex for me to even begin to analyse. Perhaps you could make maps of a smaller area that still exhibits the issue. --Redrose64 🌹 (talk) 17:52, 24 July 2024 (UTC)
- Hi MaxA-Matrix, It may be because of the use of mix-blend-mode:luminosity.
- For example, in File:Kudmali_language_region.svg, path6044 has style="display:inline;overflow:visible;mix-blend-mode:luminosity;fill:#ff8080;fill-opacity:1;stroke:#808080;stroke-width:0.8;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
- According to http://stackoverflow.com/a/67899186 , rsvg has trouble with some mix-blend-modes. cmɢʟee⎆τaʟκ 23:50, 24 July 2024 (UTC)
- @Cmglee, thank you for identifying the issue. I have removed those parameters, and now it renders perfectly. ~ MaxA-Matrix 🗨 08:03, 25 July 2024 (UTC)
- My pleasure – glad it's cmɢʟee⎆τaʟκ 15:53, 25 July 2024 (UTC)
Resolved
- Hi MaxA-Matrix, Now that
mix-blend-mode:
has been mentioned, that was definitely the problem. It is not part of the SVG 1.1 spec, in fact it is part of Compositing and Blending Level 1, a CSS module that has not yet reached the status of a W3C Recommendation (it's a W3C Candidate Recommendation Draft). I have mentioned before that anything that is not explicitly described in either SVG 1.1 or Cascading Style Sheets, level 1 is unlikely to work as intended, if at all. --Redrose64 🌹 (talk) 17:17, 25 July 2024 (UTC)
- Hi MaxA-Matrix, Now that
- My pleasure – glad it's
- @Cmglee, thank you for identifying the issue. I have removed those parameters, and now it renders perfectly. ~ MaxA-Matrix 🗨 08:03, 25 July 2024 (UTC)
Text regression bug in new rsvg
[edit]Just to let developers know, the new rsvg causes text
with text-anchor="middle"
and multiple tspan
with different font-size
to be mushed together as in http://upload.wikimedia.org/wikipedia/commons/thumb/archive/9/9b/20240814213354%21Tennis_racquet_principal_axes.svg/200px-Tennis_racquet_principal_axes.svg.png .
I've worked around it with text-anchor="start"
(the default) but it would be good if it behaved similarly to popular browsers.
Cheers, cmɢʟee⎆τaʟκ 21:39, 14 August 2024 (UTC)