Wikipedia:SVG help Information

From Wikipedia
https://en.wikipedia.org/wiki/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

  • 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

Common problems

Testing for problems

The following SVG checkers may help you to detect SVG problems before you upload:

flowRoot does not appear

a picture containing SVG1.2-valid flowRoot

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.

font-family issues

Rendering anomalies of small fonts in thumbnail views
Fallback fonts

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 font-family 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: font-family="Liberation Sans,Arial,Helvetica,sans-serif", 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 font-family="Arial,DejaVu Sans" 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.)
  • Converting the text into paths increases file size, and is therefore generally disfavored (except for text logos, etc.).
  • Group the text, create a copy, and convert the copy to paths. Then either:
    1. 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
    2. 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#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.

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>

or with

<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

Normal image
Broken image

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.

arc flags

If circle-segmentes are distorted it is often due to reduced spaces between arc-to-flags, see phab:T217990 for details.

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.

Rendering files

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:

  • 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.)

Rendering OpenOffice.org SVG files

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 tspan elements. (E.g. change <tspan x="17583 17917 " y="10943"> to <tspan x="17583" y="10943">.)
  • [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)
Original text Replacement text
Sans embedded DejaVu Sans
tspan x="([0-9]*) ([0-9 ]*)" tspan x="\1"

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 "userSpaceOnUse" for the parameter maskUnits correctly. To bypass this issue, replace maskUnits="userSpaceOnUse" with maskUnits="-10% -10% 120% 120%", and the SVG mask will render properly on Wikipedia.

parameter stroke-dasharray

The librsvg-library does not accept a stroke-dasharray parameter with values separated by spaces. Replace all spaces with commas to bypass this issue: e.g. stroke-dasharray="2 3 2 4"stroke-dasharray="2,3,2,4"

The XML code for Versions 5+ of this SVG image file (17 KBytes; 2021-02-25) was automatically generated within Version 2.2 of the "Line graphs" spreadsheet.
The XML code for this SVG image file (6 KBytes; 2021-04) was automatically generated within Version 1.1 of the "Column graphs" spreadsheet.

I've uploaded .xlsx (Microsoft Excel) spreadsheets that automatically generate XML code for graphs/charts in SVG format.

You simply paste your X-Y data into the spreadsheet, and specify image dimensions, number of grid lines, font sizes, etc. The spreadsheet automatically generates a column of XML code that you simply copy and paste into a text editor and save as an ".svg" file. It reduces file size by avoiding the "extra stuff" that Inkscape inserts, and should save you time.

Feedback and suggestions on my talk page are welcome. RCraig09 ( talk) 23:41, 19 February 2021 (UTC)

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 Information

Create a new request

UE logo.svg

I uploaded File:UE_logo.svg after extracting it from this PDF with Inkscape, however the images rendered by librsvg (such as in the revision thumbnails and the article page) have letter misalignment.

I'm sure this is bad letter-alignment on small font-size, but is there an easy way to fix the font size for each of these text elements with (or without) Inkscape? I have tried editing the SVG text using simple find and replace, but I run into problems adding scale(0.1) where there are already rotation transforms, and assume I can't increase the viewbox size for a non-free image. Soapwort ( talk) 05:33, 31 March 2021 (UTC)

For whatever reason ungrouping certain elements has helped ( before, after), but the alignment still does not match the original. Soapwort ( talk) 06:23, 31 March 2021 (UTC)
Part of the problem is that the 7.6394px font-size is lower than the recommended 20px. To ensure that the baselines are aligned, I centred everything on the middle of the logo, and use rotate and translate transforms to move the letters in place (y="0.7ex" moves the origin of each letter to approximately its centre):
  <g font-family="Arial" font-weight="bold" font-size="7.6394px" text-anchor="middle" fill="#dc2225" transform="translate(-140.3,-528.1)">
   <text transform="rotate(269.7) translate(0,-35.4)" x="0" y="0.7ex"><tspan></tspan></text>
   <text transform="rotate(278.5) translate(0,-35.4)" x="0" y="0.7ex"><tspan>T</tspan></text>
   <text transform="rotate(286.5) translate(0,-35.4)" x="0" y="0.7ex"><tspan>H</tspan></text>
   <text transform="rotate(295.3) translate(0,-35.4)" x="0" y="0.7ex"><tspan>E</tspan></text>
   <text transform="rotate(307.5) translate(0,-35.4)" x="0" y="0.7ex"><tspan>U</tspan></text>
   <text transform="rotate(316.3) translate(0,-35.4)" x="0" y="0.7ex"><tspan>N</tspan></text>
   <text transform="rotate(322.6) translate(0,-35.4)" x="0" y="0.7ex"><tspan>I</tspan></text>
   <text transform="rotate(329.1) translate(0,-35.4)" x="0" y="0.7ex"><tspan>O</tspan></text>
   <text transform="rotate(338.4) translate(0,-35.4)" x="0" y="0.7ex"><tspan>N</tspan></text>
   <text transform="rotate(350.2) translate(0,-35.4)" x="0" y="0.7ex"><tspan>F</tspan></text>
   <text transform="rotate(358.4) translate(0,-35.4)" x="0" y="0.7ex"><tspan>O</tspan></text>
   <text transform="rotate(  7.7) translate(0,-35.4)" x="0" y="0.7ex"><tspan>R</tspan></text>
   <text transform="rotate( 20.1) translate(0,-35.4)" x="0" y="0.7ex"><tspan>E</tspan></text>
   <text transform="rotate( 28.1) translate(0,-35.4)" x="0" y="0.7ex"><tspan>V</tspan></text>
   <text transform="rotate( 36.2) translate(0,-35.4)" x="0" y="0.7ex"><tspan>E</tspan></text>
   <text transform="rotate( 45.2) translate(0,-35.4)" x="0" y="0.7ex"><tspan>R</tspan></text>
   <text transform="rotate( 53.4) translate(0,-35.4)" x="0" y="0.7ex"><tspan>Y</tspan></text>
   <text transform="rotate( 61.6) translate(0,-35.4)" x="0" y="0.7ex"><tspan>O</tspan></text>
   <text transform="rotate( 71.1) translate(0,-35.4)" x="0" y="0.7ex"><tspan>N</tspan></text>
   <text transform="rotate( 80.0) translate(0,-35.4)" x="0" y="0.7ex"><tspan>E</tspan></text>
   <text transform="rotate( 89.9) translate(0,-35.4)" x="0" y="0.7ex"><tspan></tspan></text>
   <text transform="rotate( 78.7) translate(0, 35.4)" x="0" y="0.7ex"><tspan>M</tspan></text>
   <text transform="rotate( 69.3) translate(0, 35.4)" x="0" y="0.7ex"><tspan>E</tspan></text>
   <text transform="rotate( 60.0) translate(0, 35.4)" x="0" y="0.7ex"><tspan>M</tspan></text>
   <text transform="rotate( 50.3) translate(0, 35.4)" x="0" y="0.7ex"><tspan>B</tspan></text>
   <text transform="rotate( 42.0) translate(0, 35.4)" x="0" y="0.7ex"><tspan>E</tspan></text>
   <text transform="rotate( 33.3) translate(0, 35.4)" x="0" y="0.7ex"><tspan>R</tspan></text>
   <text transform="rotate( 24.7) translate(0, 35.4)" x="0" y="0.7ex"><tspan>S</tspan></text>
   <text transform="rotate( 12.7) translate(0, 35.4)" x="0" y="0.7ex"><tspan>R</tspan></text>
   <text transform="rotate(  3.8) translate(0, 35.4)" x="0" y="0.7ex"><tspan>U</tspan></text>
   <text transform="rotate(354.8) translate(0, 35.4)" x="0" y="0.7ex"><tspan>N</tspan></text>
   <text transform="rotate(343.0) translate(0, 35.4)" x="0" y="0.7ex"><tspan>T</tspan></text>
   <text transform="rotate(334.5) translate(0, 35.4)" x="0" y="0.7ex"><tspan>H</tspan></text>
   <text transform="rotate(328.5) translate(0, 35.4)" x="0" y="0.7ex"><tspan>I</tspan></text>
   <text transform="rotate(322.9) translate(0, 35.4)" x="0" y="0.7ex"><tspan>S</tspan></text>
   <text transform="rotate(310.7) translate(0, 35.4)" x="0" y="0.7ex"><tspan>U</tspan></text>
   <text transform="rotate(301.9) translate(0, 35.4)" x="0" y="0.7ex"><tspan>N</tspan></text>
   <text transform="rotate(295.6) translate(0, 35.4)" x="0" y="0.7ex"><tspan>I</tspan></text>
   <text transform="rotate(289.0) translate(0, 35.4)" x="0" y="0.7ex"><tspan>O</tspan></text>
   <text transform="rotate(279.8) translate(0, 35.4)" x="0" y="0.7ex"><tspan>N</tspan></text>
  </g>
You can change the rotate(...) values to change the spacing along the arcs. Hope that helps, cmɢʟeeτaʟκ 10:46, 1 April 2021 (UTC)
This is an elegant solution, thanks. Using this I was able to move the decimal point in the group font-size (i.e. 76.394px) and add scale(0.1) to each text tag, fixing the alignment issues. Soapwort ( talk) 06:34, 2 April 2021 (UTC)
Good idea, @ Soapwort: I've simplified it by taking the scale(0.1) out. cmɢʟeeτaʟκ 11:20, 7 April 2021 (UTC)

Maint:Attr-user not existing

This was fixed

I recently uploaded a file with a messed-up gradient. When you see it, it looks dark when it is not supposed to be. IF you open the origin file, you can see how I intended it to look.

I noticed that this was placed in the Commons category Category:Maint:Attr-user not existing. I assume this is the problem, but I have no idea what it means. W3C validator says this image is valid. This is really confusing.

Can anyone here help? -- Diriector_Doc├─────┤ Talk Contribs 19:36, 2 April 2021 (UTC)

The file description page is in c:Category:Maint:Attr-user not existing because it has {{ Attrib|Wikipedia-logo-v2-wordmark.svg|Wikimedia Foundation}} - but Wikimedia Foundation ( talk · contribs) is not a registered user. -- Redrose64 🌹 ( talk) 13:04, 4 April 2021 (UTC)
As for the gradient problem, it's possible that you've used certain shorthand ways of adding path data, that are not recognised by librsvg (see previous threads on this page, such as Wikipedia:SVG help/Archive 7#File:Alternattiva Demokratika.svg, Wikipedia:SVG help/Archive 8#Render issue). Have you asked at c:COM:VPT or perhaps c:Commons:Graphic Lab/Illustration workshop? -- Redrose64 🌹 ( talk) 13:54, 4 April 2021 (UTC)
Fixed the gradient problem. Turns out, there was a `style=""` attribute that defined the `stop-opacity`, which my browser and my editor used to overwrite the `stop-opacity=""` attribute. I guess when the image is uploaded, MediaWiki prefers the defined attributes rather than the `style` attribute. -- Diriector_Doc├─────┤ Talk Contribs 15:00, 6 April 2021 (UTC)
The SVG spec allows either stop-opacity="<opacity-value>" or style="stop-opacity:<opacity-value>;", they are interchangeable. But as you noticed, if you have both forms in the same element and they have different values, as here:
      <stop
         style="stop-color:#fee476;stop-opacity:1"
         id="stop3858"
         stop-opacity="0"
         offset="0" />
the user agent (your browser is a user agent, and so is librsvg) has no clear indication of which one to use, and different agents may have differing rules of precedence. So, as you surmised, the correct solution is to remove one of them and so resolve the ambiguity. -- Redrose64 🌹 ( talk) 16:32, 6 April 2021 (UTC)

Missing rows of pixels

218px width
216px width

While helping @ Dirac66: with a request, I noted that the thumbnail renderer misses out pixels, the most severe being the minus sign before 1/3 on the fifth row. Some equal signs also appear as minus signs.

It seems most widths are susceptible. This issue is especially bad on mobile phone browsers: 216px works on a PC but not on Android.

I suppose I can repeat every row by thickening the text but it will unnecessarily bold the text.

Does anyone have a good solution?

Thanks,
cmɢʟeeτaʟκ 09:30, 13 April 2021 (UTC)

I think I read it somewhere, possibly in a post by RexxS ( talk · contribs), that multiples of 4px are preferred. 216 exactly divides by 4; 218 does not. -- Redrose64 🌹 ( talk) 16:53, 13 April 2021 (UTC)
Thanks, Redrose64. I'll check with RexxS. Cheers, cmɢʟeeτaʟκ 00:21, 16 April 2021 (UTC)