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.

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

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 31 August 2021).
  • Line charts (download v2.2)— Accepts up to five datasets for LINE charts (example at right) (updated 12 June 2021).
  • 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 30 April 2021).
  • 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 9 June 2021).
  • Scatter plots (download v1.0)— Accepts up to five datasets for SCATTER PLOTS (updated 14 June 2021).
  • Pie charts (download v1.0)— Accepts a series of up to 36 items for PIE CHARTS (updated 25 March 2021).

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

Not rendering SVG[edit]

Hello!

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

@Jonteemil: xmlns="http://www.w3.org/2000/svg" was missing  — Johannes Kalliauer - contrib. 16:25, 8 October 2021 (UTC)[]
Resolved
 –  — Johannes Kalliauer - contrib. 16:25, 8 October 2021 (UTC)[]

SVG multiply blending[edit]

Can someone take a look at File:Post Luxembourg logo.svg? I was able to get the multiply blending working on wikipedia, but for some reason it introduced some weird artifacts in the rendering. You can see the artifacts in the upper left corner (around the edge of the orange circle) here. Auguel (talk) 06:13, 31 October 2021 (UTC)[]

Have you tried addressing all of the errors that validator has thrown? --Redrose64 🌹 (talk) 21:56, 31 October 2021 (UTC)[]
I guess the SVG validation is run by a bot, and the validation was run on an old file. Anyway I checked my new file with an external validator and it showed some errors but they were all related to stop elements missing the offset parameter. I uploaded a new file which corrects this issue (and checked it with an external validator to confirm). But the rendering issue is still present. Auguel (talk) 22:16, 31 October 2021 (UTC)[]
Firstly, backgroundImage is deprecated. However, there is no good alternative as the link explains. I've thus added a workaround for Firefox. As for the immediate issue, it seems RSVG supports backgroundImage but has trouble antialiasing semitransparent pixels (alpha < 255). I thus initially made the background white so that the bug goes away. To retain the transparent background, I used a filter (filter_mask) to make the entire logo white, and set it as a mask. Applying it to the white-background-plus-logo group cuts out just the logo. Can someone please raise a bug report about the trouble antialiasing semitransparent pixels? Let me know if there are more issues, cmɢʟeeτaʟκ 03:07, 1 November 2021 (UTC)[]
P.S. I tweaked the colours on the text to more closely match http://posttrack.com/cdn/images/carriers/thumbnails/0162-post-luxembourg.png .
@Cmglee: Thanks. Definitely a lot to consider there. Unfortunately it doesn't seem your workaround is quite perfect. You have lost the gradient fill of the previous images. Also I don't think tweaking the colors was necessary as the initial svg was taken straight from the source (https://cdn.post.lu/postlu/babel-theme/assets/images/logo-post.svg), the only problem is that it doesn't render correctly on wikipedia. Auguel (talk) 04:01, 1 November 2021 (UTC)[]
@Auguel:@HapHaxion: I restarted from https://cdn.post.lu/postlu/babel-theme/assets/images/logo-post.svg and first worked around the arc-space bug. I had to put in two huge workarounds:
 <filter id="filter_rsvg">
  <feBlend mode="multiply" in2="BackgroundImage"/>
 </filter>
 <filter id="filter_mask">
  <feColorMatrix type="matrix" values="0,0,0,0,1 0,0,0,0,1 0,0,0,0,1 0,0,0,1,0"/>
 </filter>
 <mask id="mask_rsvg">
  <use xlink:href="#for_rsvg" filter="url(#filter_mask)"/>
 </mask>
 <g mask="url(#mask_rsvg)">
  <path d="M51 102c28.166 0 51-22.834 51-51S79.166 0 51 0 0 22.834 0 51s22.834 51 51 51z" fill="#fff"/>
  <path d="M84.92 58.509a27.304 27.304 0 0 0-3.829-13.981c1.113-7.957-.975-15.237-6.395-19.467a16.325 16.325 0 0 0-7.245-3.189c-4.343-4.546-9.757-7.178-15.59-7.095a19.592 19.592 0 0 0-11.18 3.889 23.128 23.128 0 0 0-13.467 4.122c-12.779 9.04-13.568 29.978-1.73 46.728 11.84 16.751 31.067 21.902 44.976 14.167a18.404 18.404 0 0 0 6.03-5.385 27.567 27.567 0 0 0 8.43-19.79z" fill="#fff"/>
  <g id="for_rsvg">
   <use xlink:href="#paint0" filter="url(#filter_rsvg)"/>
   <use xlink:href="#paint1" filter="url(#filter_rsvg)"/>
   <use xlink:href="#paint2" filter="url(#filter_rsvg)"/>
  </g>
  <set id="avoid_double_image_in_chrome" attributeName="visibility" to="hidden" fill="freeze"/>
 </g>
 <g id="for_browser" visibility="hidden">
  <path id="paint0" style="mix-blend-mode:multiply" d="M71.867 36.833c11.85 16.793 12.527 39.125-1.376 46.86-13.904 7.735-33.16 2.627-45.006-14.178-11.845-16.805-11.05-37.69 1.729-46.74 12.778-9.052 32.783-2.735 44.653 14.058z" fill="url(#paint0_linear)"/>
  <path id="paint1" style="mix-blend-mode:multiply" d="M77.569 48.344c.335 18.79-10.625 34.226-24.48 34.477-13.856.251-25.366-14.783-25.725-33.573-.359-18.791 10.643-34.226 24.498-34.471 13.855-.245 25.39 14.776 25.707 33.567z" fill="url(#paint1_linear)"/>
  <path id="paint2" style="mix-blend-mode:multiply" d="M73.02 62.792C62.551 76.18 46.35 80.996 36.82 73.56c-9.529-7.436-8.781-24.337 1.676-37.725 10.457-13.389 26.67-18.21 36.2-10.768 9.53 7.442 8.782 24.336-1.675 37.725z" fill="url(#paint2_linear)"/>
  <set id="avoid_double_image_in_rsvg" attributeName="visibility" to="visible" fill="freeze"/>
 </g>
  1. Since Firefox and Chrome support style="mix-blend-mode:multiply", the for_browser group retains this method. To avoid badly rendered SVG appearing in the thumbnail, it is initially invisible, but the set command reveals it in browsers, but not Rsvg, which doesn't support SMIL.
    Rsvg meanwhile supports BackgroundImage in filters, which the for_rsvg group uses. To avoid badly rendered SVG appearing in Chrome, set hides it.
  2. As in my last message, the logo is placed on a white background to work around the semitransparent-pixel-artifact bug. I then created a mask from a completely white version of the logo to mask the background off.
Hope that fixes all the problems. Let me know if anything else is awry. Cheers, cmɢʟeeτaʟκ 14:12, 1 November 2021 (UTC)[]
Many thanks to all of you for your efforts on fixing the file! HapHaxion (talk / contribs) 15:46, 1 November 2021 (UTC)[]
Yep thanks a lot cmglee. Auguel (talk) 16:30, 1 November 2021 (UTC)[]
Demonstration of antialiasing pixel artifacts on elements with a filter using BackgroundImage. On the left half, artifacts appear at boundaries with the transparent background. On the right half, the background is white, and the artifacts are absent.
My pleasure. I've created a simple SVG demonstrating the bug. cmɢʟeeτaʟκ 12:53, 2 November 2021 (UTC)[]
Resolved
 – Auguel (talk) 16:30, 1 November 2021 (UTC)[]