Wikipedia:SVG help

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search
Ark-icon.svg
Create a new request
Ark-icon.svg

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[edit]

Testing for problems[edit]

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

flowRoot does not appear[edit]

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[edit]

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[edit]

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[edit]

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[edit]

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

Further issues[edit]

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[edit]

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[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:

  • 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[edit]

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)[edit]
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[edit]

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"[edit]

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[edit]

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"

Use xlink:href=, not href= alone, in <use ___/> statements[edit]

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.

CSS selectors or identifiers must start with a letter or hyphen[edit]

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

General concept above; examples below.
Warming stripes (composite)
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 your X-Y 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. It produces lean SVG code, 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)[reply]

Click HOW TO for detailed explanation.
Click here to see examples of warming stripes embedded in different shapes.
  • Warming stripes bar chart (download v1.0) Creates a bar chart whose individual bars/columns are coloured according to Dr. Hawkins' warming stripes colour scheme. Alternate option: choose one colour for ascending bars and another colour for descending bars. One dataset only (updated 27 Jan 2022).
  • Line charts (download v2.2)— Accepts up to five datasets for LINE charts (example at right) (updated 25 Jan 2022).
  • Vertical bar charts (column charts) (download v1.1)— Accepts up to six datasets for VERTICAL BAR CHARTS (COLUMN CHARTS)—toggle between clustered and stacked charts; user can adjust "Yfloor"—the Y level (usually=0) from which columns rise or fall; user chooses to keep or ignore negative input values (example at right) (updated 25 Jan 2022).
  • Horizontal bar charts (download v1.0)— Accepts up to six datasets for HORIZONTAL BAR CHARTS—toggle between clustered and stacked charts; user can adjust "Yfloor"—the value (usually=0) from which bars extend; user chooses to keep or ignore negative input values (updated 27 Jan 2022).
  • Scatter plots (download v1.0)— Accepts up to five datasets for SCATTER PLOTS (updated 25 Jan 2022).
  • Pie charts (download v1.0)— Accepts a series of up to 36 items for PIE CHARTS (updated 26 Jan 2022).

See examples in Category:SVG diagrams created with spreadsheet.

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]

Create a new request

How can I see that an SVG image update has been changed?[edit]

Good morning, I wanted to ask if it is possible to know what has been changed from an SVG update, either on Wikipedia or by programs like Notepad++. Thank you! --KajenCAT (talk) 12:08, 26 March 2022 (UTC)[reply]

Example
@KajenCAT: As an example: I take File:Instant_insanity_nets.svg from #Weird_rendering_of_pattern
  1. Download both versions:
    wget /media/wikipedia/commons/archive/1/12/20220314025255%21Instant_insanity_nets.svg
    wget /media/wikipedia/commons/1/12/Instant_insanity_nets.svg
  2. Open both in Notepad++ (and for convenience close all other opened files)
  3. Install Compare-Plugin, see https://www.makeuseof.com/tag/notepad-compare-two-files-plugin/
  4. Notepad++ > Plugins > Compare > Compare
  5. Something similar to https://commons.wikimedia.beta.wmflabs.org/wiki/File:Screenshot_from_2022-03-26_13-14-31.png should appear (I’m currently on Linux, therefore I use vimdiff instead of notepad++, so the interface is more like https://www.thewindowsclub.com/wp-content/uploads/2021/01/compare-two-files-in-notepad.png )
 — Johannes Kalliauer - contrib. 12:26, 26 March 2022 (UTC)[reply]
Thank you, @JoKalliauer:! Now I see the diff. I'm updating the Catalan version of File:2022 Russian invasion of Ukraine.svg and and I have already translated and transcribed most of the image (legend, toponyms, ...) to Catalan. I want to do it every few days to keep it updated, but I have to do it all over again from zero. Although I have almost automated this process, I was wondering if it would be possible to simply copy the new changes from the old file to the new file and overwrite them to my translated file, just to speed up the process.
Although this plugin is very useful (and it can help me in small changes), I don't see how I can do this. I searched it on internet, but I didn't understand it very well, as my knowledge in this field is very basic. KajenCAT (talk) 13:35, 26 March 2022 (UTC)[reply]
An alternative method without installing any additional software is to use Rillke's SVGedit: after adding
if (mw.config.get('wgNamespaceNumber') === 6 && /SVG/i.test(mw.config.get('wgTitle').slice(-3))) // SVGedit on SVG files only
	importScript('User:Rillke/SVGedit.js');
to Special:MyPage/common.js, save the previous version as an SVG file, click Edit SVG on the file page on Commons, Browse for the saved file, and click Diff. Cheers, cmɢʟeeτaʟκ 22:27, 28 March 2022 (UTC)[reply]
Hi @Cmglee:, thank you very much! However, I don't see how I could copy the change of this diff to my version language. In other words, how can I overwrite the modifications in another file without modifying what has not been touched? Regards, KajenCAT (talk) 15:55, 31 March 2022 (UTC)[reply]
Hi KajenCAT, I don't think SVGedit can do that. It sounds like you wish to do a three-way merge. http://stackoverflow.com/questions/572237/whats-the-best-three-way-merge-tool links to some tools that can do that ‐ sadly, I couldn't find a free online tool. The alternative is to generate a patch and apply it to the other file. http://tools.bartlweb.net/diff claims to do this but I haven't tried it out. Hope that helps, cmɢʟeeτaʟκ 00:11, 1 April 2022 (UTC)[reply]

Issue with rendering SVG file[edit]

I'm having trouble with rendering this file when using it on a wikipedia page, I'm not sure whether its to do with resolution or if I'm dealing with a corrupt file. In lower scaling all you see is an empty space, but if you select higher scaling, all the shapes in the svg file appear.

Here is the link to the file: en:File:Solent_First_Bus_Logo.svg

Let me know your thoughtsNHPluto (talk) 13:30, 19 June 2022 (UTC)[reply]

@NHPluto: How did you create this file? What is it’s source?  — Johannes Kalliauer - contrib. 14:15, 19 June 2022 (UTC)[reply]
@JoKalliauer: You don't need to pull the resolution way down to 43 x 11, because 431 x 110 = 47,410 which is less than half of the maximum permitted 100,000 pixels. --Redrose64 🌹 (talk) 17:26, 19 June 2022 (UTC)[reply]
@Redrose64 That's true, but the guideline imho does not directly cover SVG and the actual reason was not the reduction of the preview-size, but the reduction of the numeric precision (less digits in the SVG)  — Johannes Kalliauer - contrib. 19:21, 19 June 2022 (UTC)[reply]
Number of bytes in the SVG shouldn't be an issue when you're in the 3-4 KB area - WP:DWAP. It gets converted to a PNG for rendering, in any case, which may well be larger. But it is known that our librsvg utility isn't so good when the <svg> tag specifies small values for the width= and height= attributes. I think that this is because it tries to draw a PNG using integer conversions of the various coordinates, and then upscales it with consequent pixellation. --Redrose64 🌹 (talk) 19:46, 19 June 2022 (UTC)[reply]
@Redrose64
@JoKalliauer File was created from a non-free content logo used on a company's website using this link:
https://www.firstbus.co.uk/sites/all/themes/custom/fg2015/img/logos/opcos/12.svg
Though the link is dead as of now, I have the original file downloaded before the link was deleted. I haven't had a problem uploading NFC images for minimal use on pages before so I'm very much new to this. On the page it was supposed to be on, I have also uploaded two other SVG files and they have displayed as normal. NHPluto (talk) 21:48, 19 June 2022 (UTC)[reply]
@NHPluto non-free content isn't related the the rendererror, we were talking about my second upload at File:Solent_First_Bus_Logo.svg#filehistory, which shoudn't bother you. The problem in your svg was the following line <path id="svg_3" fill="url(#SVGID_1_)" d="m447,-87c0,0.6 -0.5,1.1 -1.1,1.1" class="st2"/>, but don't ask me why.  — Johannes Kalliauer - contrib. 14:13, 20 June 2022 (UTC)[reply]