Help:SVG

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
This page is a translated version of a page Help:SVG and the translation is 30% complete. Changes to the translation template, respectively the source language can be submitted through Help:SVG and have to be approved by a translation administrator.
Outdated translations are marked like this.

Shortcut: COM:SVG

SVGファイル形式の公式ロゴ

SVG (Scalable Vector Graphics)はウィキメディア・コモンズで受け入れられるファイル形式です (Commons:File types参照) 。これは図表、地図などの写実的でない画像に適しています。SVGは描画をソースコードで記述するために修正・改良に最も適しているので、コモンズでは高く評価されています。

SVGファイルはコモンズで広く用いられています。ここでは、そのうえでのヒントを紹介します (SVGファイルを生成する手筈が既に分かっている場合、以下の他に Help:Illustrator (英語版)Help:Inkscape を確認することを検討してみてください) 。

SVGとは何か

An example of an SVG image — note that at whatever scale you view the image, its curves always appear smooth, never "jagged"

Scalable Vector Graphics (SVG) is an XML specification and file format for describing two-dimensional vector graphics (as opposed to a "bitmap" or raster graphic) in both static and animated forms. It is stored in either plain text or compressed (binary) format which is much more size efficient than most other image formats such as JPEGs or GIFs. SVGs also allow embedding of raster graphics and editable text.

librsvg

librsvg (alternatively "RSVG") is the rendering library used by MediaWiki to rasterize the SVG files into the PNG bitmap format that is served to Wikimedia pages. The displayed image is not SVG and is therefore not animated or interactive. One reason for this choice is that rendering an SVG in real-time slows down older computers or operating systems. A raster version which can be efficiently converted from the SVG source helps overcome this technical problem. Another reason is that some SVG files are large (e.g., 1 MB), but the image when displayed on a monitor might be 160×320 pixels, which would be an uncompressed 51200 pixels (153600 bytes for 24-bit color).

As of May 2023, Commons is running librsvg 2.44.10 (phab:T193352), already four years old by the time of its adoption. This is an early version of the librsvg rewrite in Rust programming language. Although it manages to fix longstanding problems such as the mask bug (phab:T55899) and provides initial support for SVG 2.0, some fixes on the upstream remain unavailable to us due to our old Debian release. See (phab:T265549) for the latest updates.

Several of librsvg's missing features and bugs impact SVG images on Commons. Consequently, SVG files need to avoid or workaround those problems. For example, librsvg does not support the text on a path feature, and librsvg has problems with top-to-bottom text. Even where librsvg works flawlessly, there can be compatibility issues if an SVG file uses a font that Commons does not have, for example.

スタイルシート

In the SVG specification, the style element MUST default its type attribute to "text/css".[1] SVG images that use style elements should explicitly set type="text/css" in their ‎<style> tag. (In other words, ‎<style type="text/css"> should be prefered of ‎<style>.) (phab:T68672)

テキストやフロー要素が表示されない

systemLanguage processing

私用の langtag qcsを使って zh-Hans を選択。
Private-use langtag qct to select zh-Hant.

RSVG は systemLanguage 属性を正しく比較しません。この属性は SVG では IETF 言語タグ(langtag)のカンマ区切りの一覧と指定されています。RSVG は、langtag の最初のサブタグ(1番目のハイフンの直前の文字グループ)のみと一致し、その後に続く国コードやスクリプトのサブタグは無視されます。 例えば RSVG だとzh-Hans(簡体中国語)とzh-Hant(繁体中国語)の区別ができません。この問題を回避するには、言語を指定する私用の langtag を使います(範囲はqaa-qtz

IETF langtag SVG markup
sr-Cyrl systemLanguage="sr-Cyrl,qsc"
sr-Latn systemLanguage="sr-Latn,qsl"
zh-Hans systemLanguage="zh-Hans,qcs"
zh-Hant systemLanguage="zh-Hant,qct"

systemLanguage 属性は、IETF langtag の一覧である必要があります。何が適切な言語タグか、若干の混乱があります。MediaWiki はセルビア語の場合、sr-ECsr-EL を採用し、これらのタグは BCP 47 ではセルビア語のうち EC地域(エクアドル)で話すものと EL (未割り当て領域)内で使われるものを意味します。 The proper langtags are sr-Cyrl and sr-Latn. The Cyrillic langtag should be before the Latin langtag to make SVG 1.1 switch processing choose the Cyrillic script if the user has stated a language preference that includes sr. (MediaWiki is starting to use proper langtags; see Phab:T117845.)

中国語はもっと複雑です。文字コードのzhはマクロ言語用のサブタグであり、中国語の地方語全てを参照します(例:ペキン官話、広東語)。前者のペキン官話の指定はzh-cmnですが、IETF レジストリ[2] では cmn が適します。同様に、後者のzh-yue も、IETF だと広東語はyueが適します。また中国語の記法も指定できます。簡体字ならHans、繁体字ならHantで指定します。 中国語の記法を区別する langtags の使い分けは明白ではありません。簡便な方法として、スクリプトにzh-Hans または zh-Hant を採用して区別します(IETF レジストリ・マークはどちらも「冗長」と位置づけますが、代替手段は推奨してません。)代替案として地方語と文字を指定します。たとえば、cmn-Hans または cmn-Hant を指定。(中国で使用されている簡体字を含む中国語)cmn-Hans-CN など地域用の langtag を追加できます。

For MediaWiki, the Serbian pages have a common source than can be rendered in either Cyrillic or Latin script. Similarly, the Chinese pages have a common source that can be rendered in either Hans or Hant. Ideally, a Chinese reader could select the Hans script, and all the images in the article would also be rendered in Hans. The desired effect would be something like

  • [[File:xyz.svg|lang=zh-hant|...]] for the zh-Hant reader and
  • [[File:xyz.svg|lang=zh-hans|...]] for the zh-Hans reader.

It is not clear whether or how this can be done in MediaWiki.

ウィキメディアコモンズのSVG画像の作成

SVG画像を作成するのに利用できるプログラムは、以下の§ Editorsに挙げられています。それ以外にも、SVGコードをテキストエディタやIDEで直接編集することもできます。

以下のセクションでは、SVGの特定の機能について説明します。

アップロードする前に: 画像の外観の検証と確認

検証

Although not a requirement on Commons, it is a good idea to run your file through the World Wide Web Consortium (W3C) XML validator (https://validator.w3.org) before you upload. The validator can find problems with an SVG file that may cause the file to render incorrectly in different platforms. For example, validation will complain about the use of flowText elements, which are nonstandard and poorly supported. However validating a file generally does not justify a reupload,[3] for exceptions see [[<tvar name="1"User:JoKalliauer/Optimization#Optimizing SVGs that have already been uploaded</tvar>|Optimizing SVGs that have already been uploaded]].

If the SVG file has a DOCTYPE declaration, then the validator will use that DTD to check the syntax. If there is no DOCTYPE (which is not required nor is it recommended),[4][5] then the validator may check that the file is well-formed XML, but it may realize the file is SVG and perform non-DTD validation by passing the file to its nu Validator.

SVG 1.1 としてファイルを検証するなら、W3C バリデータ Web ページを使うという選択肢があります。(今後の SVG 2 草案では SVG DTD への参照は削除されます。[6]

If additional namespaces are present in the SVG document, the validator will complain about them. Many tools, such as Adobe Illustrator and Inkscape, insert nodes in additional namespaces.

common prefix 名前空間 目的
cc http://creativecommons.org/ns# 許可とライセンス
cdml http://www.freesoftware.fsf.org/bkchem/cdml Chemical diagrams
dc http://purl.org/dc/elements/1.1/ メタデータ
i http://ns.adobe.com/AdobeIllustrator/10.0/ Adobe Illustrator
inkscape http://www.inkscape.org/namespaces/inkscape Inkscape
its http://www.w3.org/2005/11/its Internationalization Tag Set
rdf http://www.w3.org/1999/02/22-rdf-syntax-ns# Resource Description Format
serif http://www.serif.com/ Serif Affinity (used for object names that couldn't be stored in the standard id attribute because of unsuitable characters like space)
sodipodi http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd Graphics
svg http://www.w3.org/2000/svg SVG
xlink http://www.w3.org/1999/xlink XML Linking Language

If the W3C validator is given a file that is served with an appropriate Content-Type HTTP header, then the file will be validated as SVG 1.1+XHTML+MathML 3.0 (an option not available from the UI dropdown box). That validation is done by a second, more modern, validator, the nu Validator (https://validator.w3.org/nu). Additionally, the validation will not issue errors for the rdf namespace element trees and will use schemas to check the inkscape and sodipodi namespaces. The SVG 1.1+XHTML+MathML 3.0 validation is used by {{ValidSVG}}.

Other namespaces will still cause validation errors. The W3C nu Validator can be told to suppress errors about other namespaces with the nsfilter parameter.[7]

In addition, non-SVG 1.1 attributes will produce validation errors. The SVG 2.0 draft allows users to include arbitrary data-* attributes just as HTML 5.0 does, but the W3C validator will complain about them.

ファイルに認証された方法でタグ付けするには、§ SVG ファイルにタグ付けするをご参照ください。

画像の外観

Different software programs and different browser platforms may render the exact same SVG file in slightly different ways. The way you see your final image in a vector image editor may not reflect how that image will look once it is uploaded to Commons and is viewed by others. Also, all SVG images are automatically converted to PNG files when used in a Wikipedia article, and this may affect how the final image looks as well. As an example of the former, in an image containing a series of very fine strokes, those strokes will probably look much more bold and thick in the editor than they will once the image has been converted to SVG and viewed in a web browser.

Those who create SVG files should consider saving their work in SVG format and then opening that same image using two or three different browsers to verify that it is rendering as intended. A similar check can be done by opening the file in other image editing programs as well.

To preview how an SVG will be rendered to PNG on Commons, go to Commons SVG Checker.

The reasons why the same file becomes rendered differently depending on context is a result of how these contexts (browsers or programs) interpret the file’s SVG code and use that code to generate the image. Aim to create a "least common denominator" SVG that renders correctly no matter what browser is used to open it, and never assume that your own image editing program is showing you what the image will really look like to other viewers. Previewing SVGs in a Web browser (rather than vector graphics editor) can reveal some problems. It is sometimes helpful in tuning and tweaking the SVG code, especially in conjunction with DOM Inspector tools.

Also, some programs will allow you to insert raster-based components into your file without warning you that if the file is converted into SVG these components will not simultaneously convert to vectors, meaning that you may need to be very careful about the sorts of filters and effects you include in an image and should check for any extraneous embedded "links" within an image before you upload the SVG to Commons. How to do this will vary from program to program.

However, if you are using Adobe Illustrator, here are examples of things which will cause Illustrator to convert a path into a raster component:

  • Any pattern applied to any fill, including patterns that are automatically included in Illustrator. You can sometimes work around this by converting any patterns you have used into rasters yourself, and then using the Image--> Trace function to convert these back into vectors.
  • Any path which contains more than one of Illustrator’s "Effects" — e.g., a fisheye warp and a freehand distort. Illustrator cannot handle two of these in the Appearance menu of any single path and will rasterize them.
  • Any path which has been altered with an Envelope-distortion. You can sometimes work around these in the same way you can work around the pattern problem mentioned above, but the results are usually disappointing.
  • Any path which has been assigned the Raster effect under the Effects menu. To retain these as vectors, you may only need to undo this effect.
  • Illustrator allows users to apply gradients to strokes in three ways: gradients within strokes, gradients along strokes, and gradients across strokes. However, only the first of these, gradients within strokes, is supported by an equivalent SVG code; any strokes containing gradients along or across them will be converted into rasters when the image is saved in SVG format.

These are just a few examples of things which will cause Illustrator to produce a raster when a vector was intended. The simpler these paths can be, the more likely Illustrator will be able to retain them as vectors.

For more information on how to check SVG files for MediaWiki, see § How SVG files work in MediaWiki.

文書宣言

<?xml version="1.0" encoding="UTF-8"?>
<svg
 xmlns="http://www.w3.org/2000/svg"
 xmlns:xlink="http://www.w3.org/1999/xlink"
 version="1.1"
 viewBox="0 0 400 300"
>

The source code of every SVG file SHOULD begin with the XML processing instruction.[8] The XML processing instruction specifies the version of XML and the character set.[9] The W3C insists that character encoding declaration SHOULD be used,[10] (the W3C's validator warns only for its absence).

The software with which you create or edit the SVG file should provide the option of choosing character encoding. UTF-8 is RECOMMENDED for internationalization as opposed to ANSI or Unicode encodings other than UTF-8. The absence of the XML declaration will lead to a mild confusion when the SVG source file on a Wikimedia server is opened in a browser: the raw XML code will be displayed instead of being rendered into an image. This is not an issue if you download the source SVG file to your device and open it locally.

A DOCTYPE declaration with its DTD is not needed and it is official not recommend to use a DTD,[5] but neither it is recommended to not use a DTD. SVG 1.0 and SVG 1.1 have DTD specifications, but SVG 2.0 will not have one. The SVG DTD will validate the SVG, but the DTD is not aware of any extensions. Consequently, a DTD validator will list as errors RDF metadata and the additional elements and attributes that Inkscape includes with its SVG output. Wikimedia servers also restrict what can be included in a DTD's internal subset, so it is no longer possible to extend the SVG DTD to include additional elements and attributes.

The svg root element should follow. It MUST specify the XML namespace for SVG, xmlns="http://www.w3.org/2000/svg";[11] without the SVG namespace, an SVG image will not render. (The default namespace is specified with xmlns.) Other namespaces may be included in the svg element. For example, if the file uses linking,[12] then the xlink namespace xmlns:xlink="http://www.w3.org/1999/xlink" should be declared.

The SVG version number SHOULD be included (typically 1.1). Software normally supplies these namespace declarations and may include other namespaces.

属性のwidthheightの既定値は"100%"であり、これにより縮尺を自動で調整できます。画像の指定がwidth="400px" である場合、画像コンテナいっぱいではなく幅 400 ピクセルで表示したいと伝えています。

残念なことに、大半のソフトウェアのツールでは、これら属性を固有の値に制限しています。svg 要素には viewBox[13] 属性を指定してください。表示ボックスは画像のどの部分を表示させるか決定します。このボックスは画像コンテナの面積に合わせて、幅と高さが転換されます。

ビットマップ

There are some valuable uses of bitmap images within SVG files, such as annotating a photograph (e.g., labeling the parts in an anatomical photograph). However, most uses of bitmaps in SVG files are not necessary and bitmaps are often better converted or redrawn as vectors. Bitmaps should be included within an SVG file if for some reason this is the best solution, but should be redrawn as vectors if this yields an overall better or more informative image. Further, other editors who come across the image on Commons may decide to apply the tag {{BadSVG}} to an SVG image containing undesirable raster-based elements.

Please think carefully about using bitmaps in SVG files, and consider converting them or redrawing them as vectors when incorporating them into an image rather than including a bitmap directly. See the talk page for further discussion of this issue. If you do decide to use a bitmap image, please be sure to embed and not link to the image; otherwise it won't render.

アニメーション

SVG画像はアニメーション化できますが、SVGはWikimediaプロジェクトで使用されるときにラスターのPNGフォーマットに変換されるため、アニメーションはSVGファイルがブラウザーに読み込まれた場合にのみ表示されます。SVGを読み込むには、記事ページから画像をクリックしてFile:ページに行き、さらに画像をクリックする必要があります。

SVGのアニメーション化する方法はもともとSMILを使用していました。最近では、CSSアニメーションが利用できるようになりました。

SMIL はブラウザー全般でサポートが減少しています。Internet Explorer はサポートしていない、Google では SMIL は2015年に非推奨、将来 Google Chrome から SMIL を完全に削除する可能性があります[14]。2018年7月時点で SVG SMIL アニメーションはほとんどのブラウザで利用でき、Internet Explorer、Edge、Opera を除外します[15]

SVG ファイルに動画と同じタグを付けるには§ SVG ファイルにタグ付けする の節をご参照ください。

題名

SVG 要素の真下にあるtitle 要素の用途として SVG 画像そのものの題名を記しますが、ただし SVG 画像内の子要素のさらに下位にも適用できます。最新版のデスクトップ・ブラウザのほとんどは、これらの題名を tooltips にポップアップ表示して読者がマウスカーソルを当てたときにオブジェクトの意味を識別でき、それはオブジェクトの横に文字ラベルがある場合にも有効です。

同様にファイル名の文字列にメッセージを織りこむこともできるものの、むしろタイトル要素のヒントになるように下線など文字装飾をするようお勧めします。 通常、XML コメントは読者に示さない技術情報に適していて、SVG ソースコードの編集をするであろう他の利用者にのみ表示させます。

現在、ほとんどのモバイル・ブラウザーは、SVG 要素の直下にあるタイトル文字列を除くと、本質的にタイトル文字列を表示できません。これはモバイル機器上でポインタを当てる要素に相当するものが存在しないからです。

<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" viewBox="0 0 50 50">
	<title>SVG 画像全体のファイル名</title>
	<g id="shapes">
		<title><span lang="en" dir="ltr" class="mw-content-ltr">Title of the "shapes" group</span></title>
		<rect x="0" y="0" width="10" height="20" fill="#f00">
			<title>矩形の題名</title><!--XML comment-->
		</rect>
		<circle cx="5" cy="5" r="3" fill="#0f0"/>
		<text x="2" y="30" text-decoration="underline">テキスト
			<title>テキストのタイトル</title>
		</text>
	</g>
</svg>

禁止された要素とスクリプティング

セキュリティ上の理由から、MediaWikiは以下のパターンを含むSVGファイルを受け付けません。

<!--not whitelisted namespaces-->
xmlns:d="http://www.w3.org/2000/02/svg/testsuite/description/"
xmlns="http://www.w3.org/1999/xhtml"
xmlns="http://www.example.org/notsvg"
xmlns="http://example.org/notsvg"
xmlns:bd="http://example.org/ExampleBusinessData"
<!--no external content-->
xlink:href="../resources/SVGFreeSans.svg#ascii"
xlink:href="animate-elem-09-t.svg"
xlink:href="url(#testPattern)"
<image xlink:href="http://example.org/image.jpg"/>
<d:testDescription href="http://www.w3.org/TR/SVG11/styling.html#StylingWithCSS">
<image xlink:href="data:image/svg+xml;base64,"/>
<!-- attributeName -->
<set attributeName="xlink:href"/>
<animate attributeName="xlink:href"/>
<set xlink:href='#s'/>
<set attributeName='xlink:href'/>
<!-- css -->
@import
url("../images/selector-types-visibility-hidden.css")
url(woffs/embeded-text-text-05.woff)
<!-- scipts -->
<script></script>
<!-- interactive -->
onactivate=""
onbegin=""
onclick=""
onend=""
onfocusin=""
onfocusout=""
onload=""
onmousedown=""
onmousemove=""
onmouseout=""
onmouseover=""
onmouseup=""

問題のあるSVGファイルをサニタイズするには、https://svgworkaroundbot.toolforge.org/ が利用できます(santicize potenitally dangerous commandsを有効化してください)。詳細はUser:JoKalliauer/IllegalSVGPatternを参照してください。

機能上の制限により、XML-Parserは以下のパターンを認識できないか、ブロックします。

<!--ATTLIST-->
<!DOCTYPE svg [
<!ATTLIST bar id ID #REQUIRED>
]>
<!--ENTITY with more than one element-->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1 Basic//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-basic.dtd" [
  <!ENTITY Smile "
    <rect x='.5' y='.5' width='29' height='39' fill='black' stroke='orange' stroke-width='2'/>
    <g transform='translate(0, 5)'>
      <circle cx='15' cy='15' r='10' fill='yellow'/>
      <circle cx='12' cy='12' r='1.5' fill='black'/>
      <circle cx='17' cy='12' r='1.5' fill='black'/>
      <path d='M 10 19 L 15 23 20 19' stroke='black' stroke-width='2'/>
    </g>
  ">
  <!ENTITY Viewport1 "<rect x='.5' y='.5' width='49' height='29' fill='none' stroke='blue'/>">
  <!ENTITY Viewport2 "<rect x='.5' y='.5' width='29' height='59' fill='none' stroke='blue'/>">
]>

外部ファイル

SVG 画像の最終版を保存する前に、そのファイル作成中に他のファイルへのリファレンス(「リンク付け」の役割)を作ったので、それらを全部、消去します。もし除去しないものが SVG 文中に残ると、レンダラは外部ファイルを探せなくて表示に失敗します。ウィキメディアではそのようなアップロードを防止しており、そのファイルを保存できません。

片付け

It’s also a good idea to remove or "vacuum" any unused definitions (defs), as these can needlessly bloat the size of the file (except when you need them for further edits, such as default templates).

There are three common SVG optimizers: scour, svgcleaner and svgo, but be aware that all three optimizers have dozens of open bugs and are not actively developed any more,[16][17][18] for more optimization options and how to use them see using Optimizers.

But be aware that tidying up is controversial and often undesired, see When is optimizing/validating files undesired? for details and reasons. Tidying up or validating does not justify a reupload[19]. Invalid elements and attributes are often necessary for correct rendering, and should not be removed[20].

Plain SVG, compressed SVG, generic specifications

Inkscape and other programs also allow users to save files in SVGZ (compressed binary SVG) format. This format is not supported on Commons and should not be applied to any images uploaded here. Such images cannot be uploaded.

In Inkscape there are three possible svg-options: "Inkscape SVG", "plain SVG" and "optimized SVG". Inkscape SVGs is the best fileformat to reedit the file in Inkscape, otherwise informations such as layer or grids will be removed, such images should be taged with {{Created with Inkscape|IMPORTANT=yes}} to show they should not be optimized. Plain SVG will be rendered identical as Inkscape SVGs and are a bit smaller. Optimized SVG uses a optimizer called scour, which can reduce the file-size even more and offers some workarounds for librsvg-bugs, such as phab:T217990[21].

テキスト・フォント

ウィキメディア上ではウィキメディアのサーバーにインストールされているフリーフォントで<text>要素を使ったテキストをレンダリングします。インストールされているフォントの一覧はmeta:SVG fontsthe raw listで見ることが出来ます。font-familyによってインストールされているfont-styleも様々です。以下の理由から、なるべく文字をアウトライン化せずにテキストとして保存してください。

  • ファイルサイズが小さく済む。
  • 情報の更新や誤字脱字の修正など文字を書き換える必要がある場合、他のユーザーでも修正しやすい。
  • 容易に翻訳することができる。パスに変換されていた場合、非常に煩雑な作業となる。Template:Translateも参照。
  • 検索エンジンはパスのアウトラインを認識できない可能性がありますが、テキストは簡単に検索できます。

また、フォントのライセンスがウィキメディアで受け入れ可能ではない場合、著作権の問題が生じます。文字をパスに変換した場合、その文字は使用しているフォントの二次的著作物になるからです。

SVG files which should not convert text to path shape may be tagged with {{Path text SVG}}. For linking text modifiable (what we have been calling "text" or "font") and text non-modifiable (i.e., path-based) versions of an SVG file use {{Vector text versions|…}}.

Demonstration of the basic steps of preserving the text before converting to path in Inkscape so the text can remain selectable (when opened in real-time in browser) and searchable (by search engine like Google).

If you still insist converting text to path for reasons like the lack of support of textPath function or rare glyph which is not present in most typefaces, you should duplicate the raw text group to overlap the converted text and add the attribute fill-opacity="0" stroke-opacity="0" to this group in order to hide the raw text. This way the text in the original SVG file can still be searched, clicked and highlighted by readers manually. opacity="0" may lead to some misunderstanding because it will make the highlight invisible while still selectable. display="none" prevents readers from searching the text without accessing the source code.

Converting text to outline (path) before exporting SVG is particularly popular among Adobe Illustrator users because the vector graphic software does not convert text-align attribute to text-anchor and the fallback fonts on Wikimedia have different font metrics than the chosen font by the image contributor. This leads to incorrect text positioning and encourages users to ignore the benefits of maintaining raw text in the vector file.

Not displayed text (Flowed Text bug)

See also: § Line wrap

Inkscape supports a feature known as "Flowed Text" which automatically wraps text to fit into the bounds of a given text box. Unfortunately this feature is part of SVG Tiny 1.2, which nobody supports. Its usage will almost certainly result in compatibility problems.[22] On Wikipedia, a flowed text box does not render at all (phab:T43424 - depending on font size and color).

[23]

To avoid this issue in Inkscape:

  • The easiest solution is to only use a single click (without dragging) to create text with Inkscape’s text tool. (In contrast when holding the mouse button and dragging the mouse to draw a text box, you're specifically telling Inkscape to use Flowed Text).

However there are some easy ways to fix this issue:

  • フロー式テキストボックスをすでに作成済みなら、平文に変換するにはText[24]「テキスト」 Text → 「変換」Convert の手順を済ませます(ただし変換後に必ず文字配置を確認、実行例全体の15%前後[25]の確率で、文字列を変換もしくは文字の配置を変更するため[26])。
  • 浮動させる文字列があり、1行だけの場合 (おそらく作業10回のうち9回はこれ) お使いのテキスト編集ソフトで平文に変換 (inkscape と見た目は同じ) してから、矩形の x 値と y 値を入れ替えるため flowRegion を `<text x=".." y="..">-タグに変えます。別の方法として、文字例-編集-スクリプト string-edit-script をUser:JoKalliauer/RepairFlowRoot#replace_the_flow-text_by_<text>_using_(Text-Editor) にあります[27]で入手すると自動処理できます。

If you accidentally created a Flowed Text box which is empty (i.e. contains no text) it’s not visible or selectable in Inkscape but it still shows up as a black rectangle on Wikipedia. To delete it there are some possibilities:

  • Use Inkscape’s built in XML editor (Edit → XML Editor) and delete all Flowed Text boxes (search for all nodes which are called <svg:flowRoot id="flowRootXXXX"> in the tree view).
  • Use a simple text editor (e.g. Notepad) and search for the text "flowRoot". Delete all Flowed Text boxes manually by removing their opening XML tag (<flowRoot ...>), their closing XML tag (</flowRoot>), and all text between two matching tags.[28]
  • 単に不可視な矩形を隠すだけなら<rect … fill-opacity="0"/>-tag (もしくは<path d="…" fill-opacity="0">-tag) に` fill-opacity="0"`[29][30] を加入します。

文字変換の制限

Comparison of SVG raw text rendering and text converted to path

フォントのスケール調整は現状では(有効な変換マトリクスの場合)、水平と垂直のサイズ調整が予想どおりの挙動ではなく不均一です(水平方向の指定を無視:マトリクスから算出したフォントの高さのみ有効)。その波及効果は、幅の狭い・縮小済みの場合、あるいは他のフォントに対応して幅が拡張してある場合、文字列の幅が想定とは違って、文字ボックスからあふれてしまう(代替手段として、無償のフォントファミリーに差し替えると、既定で文字幅を縮めた・詰め打ちにした状態で使用可能。)

Text is guaranteed to be misplaced (and in some case, ugly kerning) if the resolution of the PNG render is not the same as the native dimension defined by the SVG file itself regardless of how "regular" the scaling multiplier is (e.g. 0.5, 2 or 4) (phab:T36947).[31] In any case, do not use extremely small (>10px) or large font-size and then scale the text or the whole image to your desirable size. Always begin with a reasonable font-size (unfortunately a size around 80px is preferable).[32]

Beware also with font metrics differences: an SVG file may look good when rendered directly in a SVG-capable (all modern) browser under Windows or Mac OS (which can use common, but non free fonts such as Courier or Courier New), but will look other when restricted to the list of free fonts currently supported by the MediaWiki’s SVG-to-PNG renderer (or when viewed under OSes like free distributions of Linux), see also section "Font substitution and fallback fonts".

The attribute textLength isn't fully supported and could not rendered correctly. See phab:T15387.[33]

Writing mode limitation

The top-to-bottom writing mode test cases that show it works with some but not all Chinese fonts.

RSVG recognizes writing-mode property, but there are problems with some fonts on Commons (especially the default font). That some fonts work suggests that the problem lies with the font rather than RSVG. The problem is the vertical spacing causes the characters to overwrite each other (phab:T65236). For example, the typical way of producing vertical text does not work:

<text x="50" y="50" writing-mode="tb-lr" font-size="15px">東涌綫</text>

The workaround is to specify a font that works rather than relying on the default Chinese font (which is probably WenQuanYi Zen Hei). Suitable fonts are Noto Sans CJK SC or AR PL UKai TW or monospace.


Font substitution and fallback fonts

How the fallback-fonts are rendered.

SVG font specifications may use a specific font family such as Arial or Times New Roman. Such a font specification usually means the user agent must have access to the font file with that name. Unfortunately, many fonts are proprietary and are not available on all operating systems. For example, not all operating systems have the proprietary Arial font. If the specific font family is not available, then some default font will be used; the default font may have a much different appearance. For the user agent librsvg, the default font is Liberation Serif.

Many user agents have a font substitution table that allows the user agent to substitute a font family that is close. To improve the font matching, SVG allows the font-family to be a list of font family names; the user agent will use the first font family that it recognizes. The graphic artist might list similar Microsoft, Apple, and Unix fonts to improve the chance of the user agent having the desired font. Additionally, SVG supports the CSS generic font family specification.[34][35] That means most SVG user agents should support the generic font families of serif, sans-serif, cursive, fantasy, and monospace. It is good practice to use a generic font family as the last entry in the font family list. For the librsvg on Commons:

  • sans-serif maps to DejaVu Sans
  • serif maps to DejaVu Serif
  • cursive maps to the uninteresting DejaVu Sans
  • fantasy maps to the uninteresting DejaVu Sans
  • monospace maps to DejaVu Sans Mono

On Commons, librsvg has the fonts listed in m:SVG fonts#Latin (basic) fonts comparison. Using just those fonts will get good results in Wikipedia articles that display their images using librsvg, but graphic artists should also be aware that SVG files may be displayed by other user agents. Consequently, it is best to use common font families (such as Arial) or a list of font families that ends with a generic font family (such as Trebuchet, sans-serif).

The font metrics for generic font families such as sans-serif will likely vary widely on different user agents. In graphic illustrations metric exact text elements are often important and Arial can be seen as de-facto standard for such a feature. Adding both Arial and sans-serif as fallback fonts will help the SVG to be displayed with best effort on machines that do not have or substitute Arial. To make the SVG file independent of Arial, change all occurrences of font-family: Arial to font-family: 'Liberation Sans', Arial, sans-serif.

If you are using non-Western characters, you should define those typefaces preceding Liberation Sans. For example, if your text contains Chinese characters, font-family definition should be: ‘ Liberation Sans, Arial, WenQuanYi Zen Hei, SimHei, sans-serif’. In this case, western fonts are put in the front because the quality of Western characters in Chinese fonts is often low, and we want to use the higher-quality ones first.

  • Inkscape begins supporting fallback fonts from version 0.91.
  • Adobe Illustrator version 18.1.1 or earlier (probably in later versions as well) does not support fallback fonts, so the SVG file has to be manually updated in a text editor after it is saved.
defined font Wiki-fallback possible fallbackdefinition, which look similar (works on Wikimedia/Windows/Linux/Mac)
[-no definition-] Liberation Serif
serif DejaVu Serif[36]
Times New Roman Liberation Serif font-family="Liberation Serif,Times New Roman,Times,Times-Roman,serif"
sans-serif DejaVu Sans[36]
Arial Liberation Sans font-family="Liberation Sans,Arial,Nimbus Sans L,Helvetica,sans-serif"
Helvetica Nimbus Sans L font-family="Nimbus Sans L,Ubuntu,Liberation Sans,Helvetica,Arial,sans-serif"
Calibri font-family="Liberation Sans,Carlito,Calibri,Segoe UI,Myriad,UnDotum,Optima,Tahoma,Arial,sans-serif"
Courier New Liberation Mono font-family="Liberation Mono,Courier New,Courier,monospace"
monospace DejaVu Sans Mono
[-everything unknown-] DejaVu Sans

Layout with text and tspan elements

Although you can use only the text element to render simple text in the image, the tspan element can be useful to handle text which the position of the word is dependent to the other.[37] A tspan element must be nested within the text element, and then more tspan can be nested within this tspan, all styling defined in the parent text element will be inherited by its child tspan elements. For example:

<g font-size="12px">
  <text font-weight="bold" x="10" y="10"><span lang="en" dir="ltr" class="mw-content-ltr">Wikipedia hosts knowledge</span>
    <tspan fill="blue"> <div lang="en" dir="ltr" class="mw-content-ltr">
contributed
      <tspan text-anchor="end" dy="12"> by volunteers</tspan>
</div>
    </tspan>
  </text>
  <text font-style="italic" x="15" y="30"><span lang="en" dir="ltr" class="mw-content-ltr">Wikimedia Commons hosts free media files for all sister projects.</span></text>
</g>

The primarily difference with the "g nesting text" structure is that few important text layout behaviors are exclusive to tspan: When multiple text elements are lined up consecutively, they still position themselves independently; if multiple tspan elements are lined up consecutively but the second and subsequent tspan elements are not given absolute x coordinate, text of these tspan elements will line up horizontally right next to the end of the character of prior tspan in the same text element.

しかしながら、tspan の使用は回数を多くしないのがコツであり、text 要素内のすべてのtspan 要素に単一の絶対X座標をきちんと定義している場合も対象です。というのも、既定の xml:space 定義によると(text もしくは tspan内部の)改行では、その直後の半角スペースを自動で空白記号に痴漢するからです[38]。複数個の改行マークが偶然、連続した場合に処理しても、空白記号1件になります。これは、改行マークの後に絶対X座標付きのtspan 要素が置いてあり、左寄せであった場合に限定されます(既定値としての text-anchor=start)。もしxml:space'preserve' 値を指定した場合、librsvg によってインデントを長い タブ記号に変換され、長さは半角スペース記号8文字分です。XML編集ソフトウェアのほとんどに自動フォーマットもしくはインデント繰り返し機能(インデントの書式設定)が組み込んであり、編集ソフトウェアは新しい XML 子タグごとに自動でインデントを作成します。そのような tspan の使用法が SVG ファイルに含まれているなら、インデントの繰り返しは慎重に。

The behaviors in different SVG renderers to this issue varies much and is usually inconsistent to the W3C specification (also the 'preserve' value of xml:space will be deprecated in SVG 2.[39]). The only problem with librsvg is that it never converts the line break alone into space no matter which value of xml:space is given if there is no trailing space or indent before the tspan tag. Except for librsvg, nearly all modern browsers always add the converted space character right after the preceding text, this is the reason why the end or middle values of text-anchor property always align the text 1 space leftward because the new line and/or the trailing tab or space after the closing tspan tag is converted to an unexpected space character.[40]

Re-indentation XML Code Result
Before
<text>
  <tspan>O</tspan><tspan>n</tspan><tspan>e</tspan>
</text>
One
After
<text>
  <tspan>O</tspan>
  <tspan>n</tspan>
  <tspan>e</tspan>
</text>
O n e

Inkscape is buggy to render tspan, for example, inheriting text-anchor property from the first tspan element incorrectly for the subsequent tspan elements even if the property is specifically given a value in all tspan elements.[41] In such case, simply revert the "text nestling tspan" structure to just "g nestling text". Inkscape also defaults to xml:space="preserve" to deal with space between tspan. If you are completely concern with how your SVG appears in Inkscape but prefer the default xml:space handling, use &#160; to replace each general space so it will not be hidden in Inkscape.

If you are generating an SVG using Adobe Illustrator, you will be given options to "Output fewer <tspan> elements" and "Use <textPath> element for Text on Path" during the save dialog. To maximize the consistency of the appearance of your font across browser platforms, you should place a check mark next to the former and make sure there is no check mark next to the latter. If you do not do this, the kerning of some of your letters may cause them to overlap (depending on your browser).

Line wrap

SVG 1.1 does not provide any form of line wrap (either hard or soft). Any line wrap should be done manually by repositioning new text or tspan elements with the same absolute x coordinate and a new y coordinate. For tspan elements, the next line's y coordinate can be set with the dy attribute. Although textPath can handle a similar situation,[42] this element is not supported by librsvg/Wikimedia (phab:T11420).

A draft of SVG 1.2 did address line wrapping, but there is little support.

SVG 2.0 の下書き版は線分のラッピングができますが、2018年5月時点で未対応なのは Chrome、Firefox、Edge、librsvg です。

Font styling class

Usually it is simply gratuitous use of the ‘style attribute’. To ease the process of updating font-family for every text or tspan elements, you can define the font CSS class(es) within ‘style element’ and apply the class property in elements like this:

<style type="text/css">
text {font-size:12px; font-family:Liberation Sans, Arial, sans-serif} <!-- <span lang="en" dir="ltr" class="mw-content-ltr">General font styling</span> -->
.small {font-size:9px}
.special {fill:#f93500; font-weight:bold}
.title {font-size:14px; font-weight:bold; font-family:Liberation Serif, Times New Roman, serif}
.italic {font-style:italic}
</style>
<text class="title" x="10" y="20">Qridfs</text>
<text x="10" y="30">Rfnkl fgkj qljf fgk gskla</text>
<text class="small">
  <tspan x="15" y="40">Dfj fdmnkl</tspan>
  <tspan x="15" dy="12" class="italic">Akgfld fkdngf mna</tspan>
</text>
<text class="special" x="10" y="60">Tcjgh xlij qpfj</text>

CSS class defined in ‘style element’ can also be used for other SVG elements (e.g. g and path) despite the misleading type="text/css" attribute. Even if one particular style is defined once in the SVG, it is still advised to replace the style with class for a tidier layout of XML codes.

Contrary to popular belief the style attribute does not separate content from presentation, and unless you need to override properties set by a CSS selector, it is best to use the SVG formatting attributes instead (e.g. <path fill="#fff" stroke="none"/> instead of <path style="fill:#fff;stroke:none"/>).[43] However, if you need to override the element style defined in style element, you do need to employ style attribute. If you need to override the style for text element without style attribute, you can use a tspan element container to nest the text you need to override the style, presuming there is nothing predefined in style element for tspan element.

Note
  • phab:T68672 – CSS style element get ignored if the default value type="text/css" is omitted.
  • phab:T43423 – CSS child selectors are not supported by librsvg.
  • phab:T68551 – CSS classes on text elements get not inherited on child tspan elements. If you want this, you need to add a separate class for tspan as well, or use simply groups (but not in the text element as it Scour unfortunately does).

Text with background edge

Sometimes the text might be unreadable because the background color has low contrast with the font color or the pattern is too complicated that confuses the reader. This can be solved by duplicating the text in exactly the same position, but the back text rendered with stroke and the fore text without it like this:

<text style="font-size:12px">
  <tspan x="10" y="20" style="stroke:white; stroke-width:3px; stroke-linejoin:round;"><span lang="en" dir="ltr" class="mw-content-ltr">Placeholder</span></tspan>
  <tspan x="10" y="20"><span lang="en" dir="ltr" class="mw-content-ltr">Placeholder</span></tspan>
</text>
  • "stroke-linejoin:round" is defined to avoid sharp corner of the text stroke.

The problem with applying stroke and fill to the same text element is that the stroke will be rendered over the main body of text, making it otherwise unreadable if the font is too small but requires a larger stroke to be distinguishable from the background.

SVG filters can be used to draw the text over a dilated version of the text. The filter first expands the text, sets the color of the expanded text, and then draws the original text over the dilated version. One filter can be defined, and that filter can be used by several text blocks:

<filter id="textBack">
  <feMorphology in="SourceAlpha" operator="dilate" radius="1" result="bloom" />
  <feFlood flood-color="white" flood-opacity="1" result="flback"/>
  <feComposite in="flback" in2="bloom" operator="in" result="surround" />
  <feMerge>
    <feMergeNode in="surround" />
    <feMergeNode in="SourceGraphic" />
  </feMerge>
</filter>
<text x="10" y="50" filter="url(#textBack)">gibberish</text>
<text x="10" y="70" filter="url(#textBack)">more gibberish</text>

SVG フィルターを使う方法でも文字を囲む背景の透明な矩形のサイズを決めることができます。矩形を塗ってからそのあとで文字をペイントするよりもフィルターで指定するほうがエラーに自動対処できます。矩形の大きさを固定してしまうと、文章に採用したフォントがはみ出してしまうかもしれません。あるいは文章の変更ごとに矩形の大きさを調整する必要が発生します。たとえば、文章を翻訳すると矩形を変える可能性があります。フィルターの採用によってサイズは自動で調整されます。

<filter id="rectBack" x="-2%" y="0%" width="104%" height="100%">
  <feFlood flood-color="white" flood-opacity="1" result="rect"/>
  <feMerge>
    <feMergeNode in="rect" />
    <feMergeNode in="SourceGraphic" />
  </feMerge>
</filter>
<text x="10" y="50" filter="url(#rectBack)">gibberish</text>
<text x="10" y="70" filter="url(#rectBack)">more gibberish</text>

Outlining text can be done without filters by explicitly rendering the text twice. The first time, the text is rendered with a white stroke to set the outline. The white outline erodes the text. The text is rendered a second time, but this time the text is not stroked. Consequently, the characters are rendered full size (without erosion).

If you have lot of text that needs to be rendered with a stroke background, you can manually include the text within <g>, <text> and <tspan> elements. The <g> element which will be rendered underneath, apply the stroke, then <use> the text group of <text> element without a stroke and fill the font with contrasting color:

<g style="stroke:white; stroke-width:3px; stroke-linejoin:round">
  <text id="text_group" style="font-size:12px">
    <tspan x="10" y="80"><span lang="en" dir="ltr" class="mw-content-ltr">Placeholder 1</span></tspan>
    <tspan x="10" y="95"><span lang="en" dir="ltr" class="mw-content-ltr">Placeholder 2</span></tspan>
  </text>
</g>
<use xlink:href="#text_group" style="fill:black; stroke:none"/>

W3C includes paint-order property in SVG 2.0 which allows the order to render the attributes of "fill", "stroke" and "markers" within one element arranged by the user manually, instead of following the default mandatory order.[44]

Mozilla Firefox もこの属性を試験的に採用しましたが、SVG 2.0 の安定版が公開されるまで既定では無効になっています。この機能はまた Firefox.[45] で about:config の入力値で有効にできます。

Gradients

Mozilla Firefox が原因の正しくないレンダリング。

Inkscape v0.46 の利用者であれば、画像が完璧に表示され「グラデーションを埋める」というメッセージが出ること、ブラウザの Opera や Firefox のブラウザだと「画像が乱れる」と気づくはずです。原因としてあり得るのは、グラデーションの最終の「stop」opacity set to 0. 格レーデントの最後の"ストップ"の不透明度の設定が 0 ではないでしょうか。Inkscape はこの最後のストップを無視するように見えますが、Firefox 3.0.6 と Opera 9.36 は両方とも、塗りつぶしたオブジェクト内の白い境界線としてレンダリングします。解決策は、最後のストップを削除するか(おそらく誤って作成された)、不透明度(および色)の数値を変えて、画像がブラウザで正しくレンダリングされるように修正します。

Note that Inkscape adds a JavaScript polyfill to SVG images containing mesh gradients. Scripted SVG images cannot be uploaded to Wikimedia Commons, but removing the JavaScript code will break the gradients.

Adobe Illustrator CS5、CS6、CC を採用しブラウザの Firefox を併用すると、グラデーションを含む Illustrator の「シンボル」は Commons PNG ファイルとして通常どおりレンダリングされるのに、これらのシンボルは SVG ファイル自体を Firefox で 開くと、空白で表示されると気づくかもしれません。他のブラウザでは — Google Chrome や Internet Explorer でさえ問題はなく、Illustrator の SVG 形式のロゴを正しいグラデーションでレンダリングするものの、2005 年以来、Firefox の設計者にとって既知のバグでこれまでのところ適切に修正できていないため(Mozilla の Bugzilla bug 376027 およびその他のレポート)、Firefox ではそのようなロゴを空っぽの形で表示します(グラデーションのないシンボルの線分やシンボル・パスには影響しません)。

Adobe Illustrator users should also note that any Illustrator "symbols" containing paths with both a gradient and a filter will be rendered as a PNG in Commons only within the first instance of the use of that symbol. Subsequent use of a symbol containing these paths will render the paths (though not the entire symbol) as blank (neither gradient nor filter nor fill nor stroke will be applied).

Blurring

Comparison of gaussian blur filter effect between Google Chrome and Wikimedia. (Source SVG file)

Wikimedia’s SVG renderer currently supports various filter effects, but some effects such as gaussian blur (feGaussianBlur) behave differently when the blurred object exceeds the edge of the actual image. The current version of RSVG will treat the cropped edge as the actual edge of the object to apply the effect (as if the object has applied clipPath before applying filter effect), creating an undesirable filter effect against the image edge.

Size

Reducing the file size

If the file is too big, reduce/optimize it by:

翻訳

SVG ファイルは翻訳可能で、また1枚の画像を多言語化できます(訳文を埋め込むこと)。詳細は、Commons:Translation possible/Learn moreをご参照ください。

SVG に変換する

See also: Commons:Media for cleanup

SVG 以外の画像を加工するには、まずさまざまな方法で SVG 形式に変換します。プログラムの一覧は§ 変換アプリ をご参照ください。

Note: For vector images where the vectorization was done by a third party, there is the issue where the vectorization code may have its own copyright even if the depicted image itself is out of copyright or below the threshold of originality. See § Copyright for more info.

Generally, there are 3 ways to produce an SVG file, given an existing image:

  1. Regenerate it
  2. Convert it
  3. Create a new one

If you are unable to convert an image yourself, please add the tag {{Convert to SVG}} to flag that the image should be converted. Some images are not well-suited to SVG, notably continuous-tone images such as photographs. These generally should instead be stored as JPG.

Regenerate it

If the image was generated by a program (rather than drawn by hand) — for example, a chart from a spreadsheet — it may be possible to set the output format to SVG, rather than PNG or other format, and thus produce an SVG image from the same source. If possible, this is generally easiest.

Convert it

Many vector file formats can be easily converted to SVG simply by changing the format (repackaging the existing data), by using a converter program. This may be as simple as opening the file in a vector image editor and then saving it in SVG.

For raster (bitmap) graphics, this cannot be done because the image is a set of individual pixel values, not a set of strokes (vectors). For these images (notably PNG images), one can convert to SVG via "vectorization" or "tracing" — automatically generating a vector graphic from a raster image.

SVG エディタの多くは、変換履歴の機能があり、専用の変換アプリ もあります。Inkscape の場合、potrace というプログラムを使います[49][50] 確定した方法として、ビットマップファイルを開き(File → Open… (ショートカットは Ctrl-O))、次にパスを指定します Path → Trace Bitmap… (Shift-Alt-B)。オプションはいろいろあります。これを使って処理した後は、アンダーの bitmap レイヤを忘れずに除去し、ノード数を減らすためにパスの簡略化も検討したいところです(Ctrl-L)。

Adobe Illustrator also allows for the conversion of bitmap images into vectors via its Image Trace function. Care must be taken when doing so that the resulting vector image is neither ponderously large (often the result of too much conversion fidelity with regard to color and shape) nor so simple that it loses faithfulness to the original image. Converted images almost always require some manual correction after conversion. As in Inkscape, the underlying bitmap should be removed after conversion is complete.

It should also be noted that when Illustrator converts one of its files into an SVG file, it tends to convert a number of shading effects such as "inner glow", "outer glow", and gradients applied along or across a path into undesirable raster images which it then embeds in the SVG image using links. Such embedded images can often be immediately detected by viewing the image in a web browser under high zoom where they will appear cloudy or have visibly jagged edges (neither of which is ever true of a correctly rendered vector image). As these effects were originally created without regard to the W3C consortium, Adobe does not offer and is never likely to have a solution to the problem.

In order to remove raster components from an Adobe Illustrator-generated SVG prior to uploading the image to Commons, the artist must first be able to identify where Illustrator has put them. This can be done in the following way:

First finish editing an image file and save in Illustrator’s AI format (*.AI), then save it again in SVG format. During the second Save dialogue, choose to "embed" the links (for now). Then close out the image (File=>Close or Ctrl+w). Next, open the SVG version back up again, click on "Window" from the right side of the top menu bar, and scroll down to "Links". This will open up a small window containing information about each of the links (if any) which currently exist in the SVG image (whether or not Illustrator produced them). You can click any of the entries in the top half of the window and then select the "Go to link" button located in about the middle of it-- this will take you to that particular raster so that you can identify it and either remove it or replace it with a non-raster based alternative.

ご利用の画像の SVG 形式を Illustrator で表示すると、さっき保存した時の画像とは 非常に 印象が変わってしまったと思うかもしれません。これは this is because Illustrator が画像ファイル作成中に特定のコード類を作成して保存、それを表示しようとしてもうまく行かなかったせいです(SVG 形式は Illustrator 最適ではなく Adobe Illustrator=AI 向き)。AI 形式のファイルなら、Illustrator も問題なく正しく表示できるし、SVG 形式だとIllustrator が作成したファイルでさえ、ときどき画像表示に苦労します。幸い、Illustrator 上では難しそうに見える SVG ファイルでも、通常はブラウザと Inkscape で表示するとレンダリングが正しい見た目 になります(Firefox では前述のような不具合がたまに発生。)

Create a new one

If an image cannot be regenerated or converted, the remaining option is to recreate it — draw a new SVG image, using the existing image as a model. This is manual and the most time-consuming option, but may ultimately yield the highest quality.

In all cases, it may prove useful to touch up the resulting image in an SVG editor — perhaps adding details which are hard or impossible to produce in the originating program, or simplifying or refining a complex conversion (such as simplifying a path described by 100 points to one described by 5 points, if extra points add unnecessary detail).

Once you have created an SVG image, upload it (under a new name), and tag the original raster image with {{Vector version available}}, but please do not delete the raster image or list it for deletion, as it still serves some purposes — see Commons:Superseded images policy for details.

Uploading & categorizing

Every SVG file uploaded to Wikimedia Commons should show how it was made: use template {{Inkscape}}, {{Adobe}}, {{HandSVG}}, etc.
You should check the appearance and the validity before you upload the file; use the tool Commons SVG Checker
If you are not sure or want to see first how librsvg will render your file, upload it to Test.svg

Image description pages

{{Information}} ボックスの領域をできるだけ文字で埋めるように配慮してください。画像に情報をたっぷり添えてあると、他の人がカテゴリを決めて分類する作業が楽になるし、翻訳も正しくなります。

See the § SVG software tags section for detailed information on a SVG media.

Categorizing SVG files

All SVG graphics should be sorted into the appropriate subcategory or subcategories of Category:SVG files. Please do not place images directly in the parent category as it will become overcrowded and useless (we have thousands and thousands of more than 100,000 SVG files).

サブカテゴリの並べ替えは主題ではなく、'*' を使うと、技術要素に基づかせて、アルファベット順を回避できます(「……で作成」、「アニメ画像」、「有効」その他)。

The SVG categories tree

The main tree is Category:SVG, as a part of Category:ImagesCategory:Media types.

Concerning the creation of topical subcategories, it is unnecessary to rebuild the complete hierarchy tree of Category:Topics. Normally, it is enough to gather some topics into one. For instance, Category:SVG colors could contain all color-related SVG files of Category:Colors, so it’s pointless to create Category:SVG red, Category:SVG blue and so on. Maybe some subcategories will become useful later, but stay close to the existing topics tree, and do not put any SVG files only into a SVG category: Categories are primarily for finding media, not for hiding them. Do not over-categorize.

See Commons:カテゴリ for general information.

Category naming conventions

カテゴリ名は「SVG」で始まり、続いて小文字始まりで主題を記す(固有名詞は大文字始まり)。たとえば化学に関連する SVG ファイルなら、カテゴリはCategory:SVGchemical 。命名規則がないまま長い年月が経ったせいで、この形式と一致しないファイル名が表示される場合があります。これらは時間の経過とともに修正される見込みです。

SVG ファイルにタグ付けする

See Category:SVG marker templates for all SVG markers available.
Transcluded from Commons:SVG marker templates

SVG software tags

You will find the complete up-to-date list at SVG created with ... templates
For the software used (Category:SVG graphics by software used):

 
This vector image was created with Adobe Illustrator.
 
This table was created with bin2svg.
 
This structural formula was created with ChemDraw.
 
This vector image was created with CorelDRAW.
 
This diagram was created with Dia.
 
This circuit diagram was created with the Electrical Symbols Library.
 
This vector image was created with Xfig and a Fig-to-SVG conversion tool.
 
This plot was created with Gnuplot.
 
The SVG code is valid.
 
This vector image was created with a text editor.
 
This vector image was created with Inkscape.
 
The SVG code is valid.
 
This vector image was created with Inkscape, and then manually edited
.
 
This vector image was created with MetaPost.
 
This vector image was created with Sodipodi.
 
This vector image was created with Scribus.
 
The SVG code is valid.
 
This vector image was created with a text editor.
 
This vector image was created with another SVG tool.
 
This vector image was created with an unknown SVG tool.
 
This vector image was created with Vim.
 
This vector image was extracted with Inkscape.


See #Software section for a list of programs.

SVG file tags

 
This image includes elements that have been taken or adapted from this file:
Example.svg.


Translate this file This SVG file contains embedded text that can be translated into your language, using any capable SVG editor, text editor or the SVG Translate tool. For more information see: About translating SVG files.

This file is translated using SVG <switch> elements. All translations are stored in the same file! Learn more.

For most Wikipedia projects, you can embed the file normally (without a lang parameter). The Wikipedia will use its language if the SVG file supports that language. For example, the German Wikipedia will use German if the SVG file has German. To embed this file in a particular language use the lang parameter with the appropriate language code, e.g. [[Help:SVG/ja|lang=en]] for the English version. Do not specify a lang parameter if it is not needed. The parameter may prevent the use of a subsequent translation.

To translate the text into your language, you can use the SVG Translate tool. Alternatively, you can download the file to your computer, add your translations using whatever software you're familiar with, and re-upload it with the same name. You will find help in Graphics Lab if you're not sure how to do this.


This image is an animated SVG file. The .png preview above created by RSVG for use in Wikimedia is not animated and may be incomplete or incorrect. To see the animation, open the original file. It should run in any modern browser or viewer. Recent versions of Chrome, Firefox, Microsoft Edge, Safari, and Opera all support SVG animated with SMIL. Other SVG animations can be found at Category:Animated SVG files.

Templates:Animated SVG/I18n
العربية | Boarisch | বাংলা | català | čeština | Deutsch | Deutsch (Sie-Form)‎ | English | español | فارسی | suomi | français | galego | עברית | हिन्दी | magyar | հայերեն | íslenska | italiano | 日本語 | 한국어 | lietuvių | македонски | മലയാളം | Plattdüütsch | Nederlands | occitan | português | português do Brasil | русский | sicilianu | slovenščina | svenska | ไทย | українська | 中文 | 中文(简体)‎ | 中文(繁體)‎ | +/−

.


  • SVG files containing JavaScript cannot be uploaded at present, but this template anticipates that possibility {{Scripted SVG}}.




SVG conversion tags

All Ba images in this gallery could be re-created using vector graphics as SVG files. This has several advantages; see Commons:Media for cleanup for more information. If an SVG form of this image is available, please upload it and afterwards replace this template with {{vector version available|new image name}}.


All images in this gallery could be re-created using vector graphics as SVG animation files. This has several advantages; see Commons:Media for cleanup for more information. If an SVG form of this image is available, please upload it and afterwards replace this template with {{vector version available|new image name}}.

  • To indicate that you are currently working on a vector version of a raster image you can tag it with {{Vector wip|1=~~~|time=~~~~~}}.

  • For SVG files using embedded bitmaps causing bad quality, use {{BadSVG}} and for rasters that have been superseded by a SVG file, use {{vector version available|File name.svg}}



This file has been superseded by Example.svg. It is recommended to use the other file. Please note that deleting superseded images requires consent.
new file

Sorry, this SVG file is solely a source for re-utilization, editing or printing purposes. Please do not use this graphic within Wikipedia articles! MediaWiki isn't able to render this image correctly. Some details may be missing or look wrong. When you include the image in a Wikipedia or any other Wikimedia project site's page, you may want to use the other file, until the support increases.

Help:SVG/ja File:SMW Logo.SVG

Deutsch  English  español  italiano  日本語  한국어  македонски  português do Brasil  русский  sicilianu  slovenščina  简体中文  繁體中文  +/−

{{{svgImageLabel}}}


{{{image alt}}} This SVG file is a generic template for creating new images. It contains embedded placeholder text using specific fonts that may not be available on Wikimedia Commons. This file is not intended to be embedded in a wiki page. Do not reupload this file with text converted to paths, even if the text appears unsightly in an image preview.
How to derive an image from this template
To create an image using this template:
  1. Download this SVG.
  2. Open the SVG in an SVG editor and change the wording and numbering.
  3. Convert all text to a path and save as a basic or plain SVG.
  4. Upload the new SVG to Wikimedia Commons.

SVG files in MediaWiki

How SVG files work in MediaWiki

When you upload your SVG to Commons (or any other MediaWiki wiki), the software automatically produces PNG thumbnails, embedded in the articles and the description page. If you download the image (usually by right mouse clicking on the image), you will get the PNG image. If you want the SVG file you must save the link to the image instead of the image itself. This works (by right mouse clicking on the link under the image) only on the description page of the image, not on the thumbnail in the category page.

MediaWiki uses librsvg to convert SVG files to PNG files for display (SVG rendering), it has some long and well-known bugs that should be fixed, so you might want to check your file with that program before uploading. You can test the SVG with SVG Check for accurate PNG render preview and W3 XML validator for possible code errors or incompatibility of SVG elements or attributes.

詳細情報:MediaWiki SVG の制限事項

Scaling SVG files via MediaWiki

What this means: Say you want to produce a large version of your SVG for detailed maps, or using in-bitmap software like gimp, or calligraphy printed out one character per page, or something like that. You need to force MediaWiki to produce a huge PNG thumbnail, by using https://commons.wikimedia.org/w/thumb.php?f=Foo.svg&w=1000 or by doing something like [[File:Foo.svg|1000px]] in the sandbox or your talk page or somewhere else unimportant. Printing this giant PNG will look much better than if you try to scale up one of the default thumbnails! Of course, you can also use for-printing SVG software like Inkscape but sometimes that shows something other than what’s shown on-screen (black background, other fonts, etc.).

Frequently asked questions

What are reasonable dimensions to choose for my SVG images?
The absolute size of the document does not matter much, since that only affects how it is displayed when viewed by itself. The file size does not depend on the document dimensions. The image can be stretched or compressed as much as a user wants, without changing quality, or file size. With that in mind, the recommended image height is around 400–600 pixels. When a user views the full size image, a width of 600–800 pixels gives them a good close-up view, while still allowing them to fit the entire image on their screen without having to zoom in or out: while 9 × 9 pixels are too tiny, 3000 × 2000 are too large. The length of the shorter side of the PNG rendered by librsvg on Wikimedia is capped at 4096 px (i.e. if width is shorter than height, the length cap of 4096 px will be applied on the width and the height will be scaled accordingly, or vice versa), so there is no point to upload SVG image which requires that much of resolution to be readable when some of the text will be too tiny after scaling down to preview size. Smallest font in SVG image should be readable in 2000-px width at least, the largest recommended rendering resolution in the image description page. Otherwise, a raster version should be provided alongside the SVG source.
How to convert SVG file to raster format in my computer?
For SVG file which behaves incorrectly in graphic software such as Inkscape, you can simply upload the SVG to Wikimedia then save the link which provides PNG render in other widths in the file description page. You can adjust the number-px in the link to generate the desirable width of the PNG render. For image with any side larger than 4096 px, you may use any conversion tools such as RSVG-Convert with the only difference being the lack of anti-aliasing. If you want the raster image looks smoother, you may convert the SVG to PDF in RSVG-Convert then convert the PDF to raster version in Photoshop (Inkscape still presents some font problem when opening PDF). Another option without uploading SVG source to Wikimedia (due to non-free license) is to use the SVG preview on Wikimedia Toolforge which does not have the maximum side cap, although certain rendering results such as font may differ slightly.
Why doesn't my image render?
理由は複数、考えられます。ほとんどの場合、おそらく外部ファイルの参照か、ビットマップのトレースの残存が原因です(Web サイトがこのもう1つのファイルを検出しようとしてレンダリングが停止するため)。問題解決には、最終バージョンの保存前に、必ずエディタで他のファイルへの参照をすべて削除 してください。 ビットマップファイルを処理する必要があるなら、Inkscape の画像埋め込み機能ですべて処理できます(エフェクト・メニュー → 画像 → 全ての画像を埋め込む)。ぼかしなど特殊効果も使えます。現状、残念ながら librsvg では十分に対応できません。前述の§ PlainSVG、圧縮 SVG、一般仕様 も参照してください。
Where can I get extra help with SVG images?
Try Commons:Graphic Lab if you have a problem with an individual image. Commons:Graphics village pump can be useful for SVG discussion (as well as graphics in general). Often SVG enthusiasts will be around on those pages, and are more than willing to help.
How do you change the document size in Inkscape?
文書のサイズは A4 判のページを基準にします。拡大も縮小も文書サイズは矩形の縦横を希望の大きさに設定して、矢印ツールで選択します。次にファイル → 文書プロパティ と進んでカスタムサイズ欄のページを選択に合わせる (Fit page to selection) を選択、OK を押します。これで「選択用」の矩形は消去して、作ったばかりのこの要素に配置する他の要素の移動やサイズ変更の作業に移ります。(File → Document Properties、Custom Size → Fit page to selection → OK)
My text is appearing as little blocks, or isn't showing up at all after uploading to Commons!
If you use "Flowed Text" in Inkscape, it will not render at all. Flowed text boxes are created when you click and drag to make you text box. To avoid this, just click once to position your cursor and then type your text. To convert a flowed text box to a normal text box, go to the "Text" menu and choose "Convert to Text".
If this still doesn't work, some text features of Inkscape are not supported by MediaWiki’s renderer, such as text-on-path. If you are not using flowed text and still have problem, convert the text to paths. Do this by selecting the command Path → Object to Path. This will convert the text to paths. Save as plain SVG, and reupload your file.
My arrowheads/dashed lines are appearing as little blocks, or aren't showing up at all after uploading to Commons!
Check that attribute style="overflow:visible" is in tag marker and not in tag path. Some stroke features of Inkscape are not supported by MediaWiki’s renderer. Select the offending objects, and select the command Path → Stroke to Path. This will convert the strokes to paths. Save as plain SVG, and reupload your file.
背景に透明な箱があるけど、除去するには?
作業の必要がありますか? 通常はそのままで大丈夫。MediaWiki のレンダラはファイル形式を SVG から PNG へ変換するときに自動で背景色に透明な白地を使います (PNG 透過性をサポートしないブラウザなら不透過の白色で表示。) SVG 透過性が組み込みされたブラウザなら画像の背景色は全て白色 (またはサムネールならグレー背景。) 画像背景を透明にしておくと将来の編集者の作業が楽で、その画像を別の背景色の上に表示させたときに大きな白箱が出ません。しかしながら、どうしても特定の画像に特定の色の「白身」が欠かせない 場合には、画像と同寸の矩形をもう1個作り、背景色を決めて塗りつぶしてから、コマンドで背景に指定するには オブジェクト → 下層へ移動 と進みます。画像を保存すると、ソリッドな背景色が見えるはずです[51](訳注=Object → Lower to Bottom、保存)
My fonts aren't rendering correctly. What fonts are supported by the site’s renderer?
meta:SVG フォントに一覧があります。
I am using the same fonts installed in Wikimedia, but text positioning in my SVG image still looks differently between my local render and the Wikimedia render.
ローカルのレンダラがどのライブラリやバージョンを使っているかによって、対処は変わります。文字の配置その他、 SVG 要素(例えば"transform")は、レンダリングのライブラリが変わると挙動が異なることは周知の事実です。ウィキメディアのレンダラにいちばん近いものは、librsvg を採用しているはずです。ブラウザならOpera、Chrome、Safariは正確な結果を返します。FirefoxとInternet Explorer 10はやや不正確。Safariだと、フォントのスムーズ処理を有効にした場合は、もう少しきれいに見えます。
I'm drawing a flag (or some other insignia) and it asks for PANTONE or CMYK colors. What do I do?
First, if you see the words*PANTONE or CMYK, try to see if they have something called RGB. Wikimedia Commons images are used a lot on Wikimedia projects such as Wikipedia, etc, and are designed for use on computer screens. If you can find RGB colors, use them in favour of others. If you can't, you can convert the colors using your program’s own color picker, or, in the case of PANTONE, Color Finder,[2] from which you can extract RGB values for a color code. Make sure to indicate (perhaps on the talk page or image summary) which method of conversion you used, like "[Some Program] was used to convert CMYK values […] to RGB […]".

Software

Many programs can handle SVG files. You may like to try one given below, though these are not the only programs around. Some are available for free download, while others are commercial software.

As SVG is just an XML specification, it is possible to write SVG files manually in a text editor, or with your own programs/scripts.[52] In fact, many SVG images are written in text editors. An editor which can highlight the syntax is helpful. Check your work with the W3C SVG validator.

Viewers

All modern web browsers render SVG natively.

変換アプリ

ほとんどの SVG エディタにはラスタをベクターに変換する機能が同梱されています(ベクトル化

  • toolforge:convertとは、PDF を SVG へ、SVG を PNG へ変換するツール
  • Autotrace(ご注意:含まれているリンクが最低1件、フィッシングサイトに奪取されてい流として)マーティン・ウェバーが2004年に開発したライブラリで以下のツールを使用:
    • ImageMagick
    • autotracer.orgは、オンラインのトレース機能で、対応するファイル形式は JPEG、GIF、PNG から SVG、PDF、EPS、AI、DXF に変換
    • Delineate(デリアネイト)は、無料の Java インタフェースで Autotrace(オートトレース)とPotrace(ポトレース公式サイトのリンク)。Potrace は Inkspace に同梱してあり、Path >Trace Bitmapメニューを参照。
  • Scribus(スクライバス、GhostScript ゴーストスクリプトと併用)は、EPS から SVG に変換
  • PDFTron PDF2SVGは、Windows 向けの商用ソフトで PDF から SVG に変換converter for
  • バートン PDF2SVG は Linux 対応で、PDF から SVG に変換、使用する無料のライブラリ2件はそれぞれ「Poppler」(ポップラー)と「Cairo」(カイロ)という
  • librsvgというレンダリングのライブラリは、メディアウィキと下記の変換ツールが採用しています。
    • RSVG-Convert は、オープンソースのツールで SVG から PNG、PDF、PS へ変換
  • Bitmap to SVG converter - ピクセルの作画を変換するのに便利
  • Vectorizer.AI, an artificial intelligence-based online tracer to convert raster image
  • PDF24 Tools, including an online PDF-to-SVG converter


エディタ

  • Inkscapeは、無料でオープンソースの SVG エディタで Windows、macOS、Linux に対応。詳細は ヘルプ:Inkscape を参照。
  • Sodipodi は、サポート終了したオープンソースで無償の SVG エディタで、対応は Windows と Linux
  • OpenOffice.org Draw, a free and open-source drawing program that can export to SVG natively, and reads SVG with SVG Plugin.
  • LibreOffice Draw, derivative of OpenOffice Draw, can import and export to SVG. May be more suitable than Inkscape for special cases such as flow charts.
  • Dia はオープンンソースで無償のダイアグラム・アプリで Windows、macOS、Unix に対応(現在、SVG エクスポートに複数のバグあり)
  • Adobe Illustrator, a commercial (and very expensive) vectory graphics editor with rich graphics features but limited SVG-specific capabilies. See Help:Illustrator for details.
  • Affinity Designer
  • CorelDraw
  • SVG エディット(扱いは GitHub)は、オープンソースで無償のWeb アプリ
  • SVGedit.js, an experimental gadget native to Wikimedia Commons
  • Vector Paint - a simple online editor useful for cropping. Note: cropping does not work properly with certain files.


Specialized app

  • Ipe はオープンソースで無償のエディタで SVG 変換機能付き、数学や工学の図・数式優れた統合を示す LaTeX 対応
  • Scour. For tidying up/create a smaller file size (in Python, also included in Inkscape).
  • Graphviz. An open source application for automatic diagram layout.
  • BKchem. A free software to draw chemical structures in SVG. Runs on Windows, Mac OS X, and Unix systems.
  • Freemind is a free and open source mind mapping application written in Java. FreeMind.
  • GeoGebra is a free and open source multi-platform mathematics software with ability to export SVG. Geogebra.
  • LibreOffice Calc (libreoffice.org), for creating bar charts, pie charts, etc.
  • Gnumeric spreadsheet, saves/exports charts in SVG format, cf. gnumeric.
  • Nano by Vecta.io - reduces file sizes
  • SVGO - reduces file sizes
  • SVGOMG - a web-based front-end for SVGO


Copyright

There is some concern that the SVG source code of images might be copyrightable as a "computer program" even if the output is an image in the public domain due to being below the threshold of originality or otherwise indistinguishable from a work that is public domain due to copyright expiration. This could mean that even though the output of an SVG, the image, is in public domain, the code could be restrictively copyrighted, and therefore inappropriate for including in Wikimedia Commons.

Elements that weigh in favor of SVG source code containing sufficient creative expression to be copyrightable might include hand-written code, complex embedded CSS, embedded comments longer than short phrases, or a large carefully selected set of control points. Elements that weigh in favor of SVG source code lacking creativity include programmatically generated code or slavish copying of a public domain source. See the following for additional context:

See also

脚注

  1. If a style element does not specify its type attribute, then the type is obtained from the svg element's contentStyleType attribute (which the SVG DTD defaults to "text/css"). http://www.w3.org/TR/SVG11/styling.html#StyleElement
  2. http://www.iana.org/assignments/language-subtag-registry/language-subtag-registry
  3. User:JoKalliauer/Optimization#SVG sourcecode edits without visual change
  4. W3C – valid DTD list – Optional doctype declarations
  5. a b Don't include a DOCTYPE declaration, W3C – It is not recommended that a DOCTYPE declaration be included in SVG documents.
  6. W3C – SVG 2.0 には(規範的な外部 )DTD なし
  7. Validator API, https://validator.w3.org/docs/api.html
  8. W3C: XML declaration
  9. W3C: SVG – Prolog and Document Type Declaration
  10. W3C: XML charencoding
  11. http://www.w3.org/TR/SVG/struct.html#NewDocumentOverview
  12. W3C: SVG linking
  13. W3C: SVG viewBox
  14. Philip Rogers (2015-04-30). 非推奨にする意図: SMIL. Google Groups. Retrieved on 2015-06-27.
  15. https://caniuse.com/#feat=svg-smil
  16. https://github.com/svg/svgo/issues/1055
  17. https://github.com/RazrFalcon/svgcleaner/issues/213#issuecomment-589801095
  18. https://github.com/scour-project/scour/commits/master
  19. User:JoKalliauer/Optimization#SVG sourcecode edits without visual change
  20. User:JoKalliauer/Optimization#Useless elements that should be kept
  21. https://github.com/scour-project/scour/wiki/Documentation#--renderer-workaround-and---no-renderer-workaround
  22. Inkscape FAQ: What about flowed text?
  23. You can change the colour, of the invisible path, which is used as the boundary of the flowRoot, similar to File:FlowRoot and flowRegion.svg, or you could also use the more general path-tag and create other shapes.
  24. User:JoKalliauer/RepairFlowRoot#replace notempty flow-text using (Inkscape)
  25. translate=".."-もしくはtext-align=".."-属性を使った場合に該当。
  26. サンプルはこちら:File:Petit Monde de Gondry, Jonze & Kaufman.svg
  27. Github からもダウンロード可能。
  28. User:JoKalliauer/RepairFlowRoot#delete empty flow-text using (Text-Editor)
  29. Category:Images with SVG 1.2 features
  30. User:JoKalliauer/RepairFlowRoot#That the black square won't get rendered (Text-Editor)
  31. Attribute viewBox in SVG element takes precedence in defining the native resolution if it differs from width and height attributes.
  32. Font-kerning: Help with file at Graphics village pump, compare also File:Fonttest-Kerning.svg.
  33. textLenght attribute in w3.org
  34. http://www.w3.org/TR/SVG/fonts.html#FontFaceElementFontFamilyAttribute
  35. www.w3.org/TR/2008/REC-CSS2-20080411/fonts.html#generic-font-families
  36. a b User:AntiCompositeNumber on phab:T180923#6557063
  37. W3C: SVG – The ‘tspan’ element
  38. W3C: SVG – White space handling 空白記号の処理。
  39. W3C: SVG 2 - The ‘xml:lang’ and ‘xml:space’ attributes
  40. librsvg still preserves this extra space character but during the middle or end text alignments, this space character is ignored.
  41. https://bugs.launchpad.net/inkscape/+bug/168023
  42. W3C: SVG – The ‘textPath’ element
  43. Avoid the ‚style‘ attribute where possible
  44. Chapter 11: Painting: Filling, Stroking and Marker Symbols. W3C (2012-08-12). Retrieved on 2012-11-28.
  45. paint-order. Mozilla Developer Network (2013-01-12). Retrieved on 2013-10-21.
  46. A Simple Trick for Optimizing SVG Files by WebpageFX
  47. 35-optimizing-svg-tools by CSS-Tricks
  48. css-tricks : understanding-and-manually-improving-svg-optimization
  49. Inkscape チュートリアル: Tracing
  50. Inkscape 公式ウィキ: Tools: Vectorize/trace
  51. A feature bug report for this exists since January 2005以降、Inkscape launchpad には機能のバグ報告あり。)
  52. Image made with C++ code by Claudio Rocchini
  53. User:JoKalliauer/SVG test suites

外部リンク