User Tools

Site Tools


projects:svg_dw
no way to compare when less than two revisions

Differences

This shows you the differences between two versions of the page.


projects:svg_dw [2013/05/26 22:05] (current) – created mkucia
Line 1: Line 1:
 +====== SVG images in DokuWiki ======
  
 +<html>
 +
 +<svg xmlns="http://www.w3.org/2000/svg"
 +     xmlns:xlink="http://www.w3.org/1999/xlink"
 +     width="15%" 
 +     height="15%"
 +     viewBox="0 0 300 300">
 +
 +  <title>SVG Logo</title>
 +  <desc>Designed for the SVG Logo Contest in 2006 by Harvey Rayner, and adopted by W3C in 2009. It is available under the Creative Commons license for those who have an SVG product or who are using SVG on their site.</desc>
 + 
 +   <metadata id="license">
 +     <rdf:RDF 
 +       xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
 +       xmlns:dc="http://purl.org/dc/elements/1.1/"
 +       xmlns:cc="http://web.resource.org/cc/">
 +       <cc:Work rdf:about="">
 +         <dc:title>SVG Logo</dc:title>
 +         <dc:date>14-08-2009</dc:date>
 +         <dc:creator>
 +           <cc:Agent><dc:title>W3C</dc:title></cc:Agent>
 +           <cc:Agent><dc:title>Harvey Rayner, designer</dc:title></cc:Agent>
 +         </dc:creator>
 +         <dc:description>See document description</dc:description>
 +         <cc:license rdf:resource="http://creativecommons.org/licenses/by-nc-sa/2.5/" />
 +         <dc:format>image/svg+xml</dc:format>
 +         <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
 +       </cc:Work>
 +       <cc:License rdf:about="http://creativecommons.org/licenses/by-nc-sa/2.5/">
 +         <cc:permits rdf:resource="http://web.resource.org/cc/Reproduction" />
 +         <cc:permits rdf:resource="http://web.resource.org/cc/Distribution" />
 +         <cc:requires rdf:resource="http://web.resource.org/cc/Notice" />
 +         <cc:requires rdf:resource="http://web.resource.org/cc/Attribution" />
 +         <cc:prohibits rdf:resource="http://web.resource.org/cc/CommercialUse" />
 +         <cc:permits rdf:resource="http://web.resource.org/cc/DerivativeWorks" />
 +         <cc:requires rdf:resource="http://web.resource.org/cc/ShareAlike" />
 +       </cc:License>
 +     </rdf:RDF>
 +   </metadata>
 +   
 +
 +   <defs>
 +     <g id="SVG" fill="#ffffff" transform="scale(2) translate(20,79)">
 +        <path id="S" d="M 5.482,31.319 C2.163,28.001 0.109,23.419 0.109,18.358 C0.109,8.232 8.322,0.024 18.443,0.024 C28.569,0.024 36.782,8.232 36.782,18.358 L26.042,18.358 C26.042,14.164 22.638,10.765 18.443,10.765 C14.249,10.765 10.850,14.164 10.850,18.358 C10.850,20.453 11.701,22.351 13.070,23.721 L13.075,23.721 C14.450,25.101 15.595,25.500 18.443,25.952 L18.443,25.952 C23.509,26.479 28.091,28.006 31.409,31.324 L31.409,31.324 C34.728,34.643 36.782,39.225 36.782,44.286 C36.782,54.412 28.569,62.625 18.443,62.625 C8.322,62.625 0.109,54.412 0.109,44.286 L10.850,44.286 C10.850,48.480 14.249,51.884 18.443,51.884 C22.638,51.884 26.042,48.480 26.042,44.286 C26.042,42.191 25.191,40.298 23.821,38.923 L23.816,38.923 C22.441,37.548 20.468,37.074 18.443,36.697 L18.443,36.692 C13.533,35.939 8.800,34.638 5.482,31.319 L5.482,31.319 L5.482,31.319 Z"/>
 +
 +        <path id="V" d="M 73.452,0.024 L60.482,62.625 L49.742,62.625 L36.782,0.024 L47.522,0.024 L55.122,36.687 L62.712,0.024 L73.452,0.024 Z"/>
 +
 +        <path id="G" d="M 91.792,25.952 L110.126,25.952 L110.126,44.286 L110.131,44.286 C110.131,54.413 101.918,62.626 91.792,62.626 C81.665,62.626 73.458,54.413 73.458,44.286 L73.458,44.286 L73.458,18.359 L73.453,18.359 C73.453,8.233 81.665,0.025 91.792,0.025 C101.913,0.025 110.126,8.233 110.126,18.359 L99.385,18.359 C99.385,14.169 95.981,10.765 91.792,10.765 C87.597,10.765 84.198,14.169 84.198,18.359 L84.198,44.286 L84.198,44.286 C84.198,48.481 87.597,51.880 91.792,51.880 C95.981,51.880 99.380,48.481 99.385,44.291 L99.385,44.286 L99.385,36.698 L91.792,36.698 L91.792,25.952 L91.792,25.952 Z"/>
 +      </g>
 +   </defs>
 +
 +   <path id="base" fill="#000" d="M8.5,150 H291.5 V250 C291.5,273.5 273.5,291.5 250,291.5 H50 C26.5,291.5 8.5,273.5 8.5,250 Z"/>
 +   <g stroke-width="38.0086" stroke="#000">
 +     <g id="svgstar" transform="translate(150, 150)">
 +       <path id="svgbar" fill="#ffb13b" 
 +         d="M-84.1487,-15.8513 a22.4171,22.4171 0 1 0 0,31.7026 h168.2974 a22.4171,22.4171 0 1 0 0,-31.7026 Z"/>
 +       <use xlink:href="#svgbar" transform="rotate(45)"/>
 +       <use xlink:href="#svgbar" transform="rotate(90)"/>
 +       <use xlink:href="#svgbar" transform="rotate(135)"/>
 +     </g>
 +   </g>
 +   <use xlink:href="#svgstar"/>
 +   <use xlink:href="#base" opacity="0.85"/>
 +   <use xlink:href="#SVG"/>
 +
 +</svg>
 +
 +</html>[[https://www.dokuwiki.org/dokuwiki|DokuWiki]] is a great tool for storing information. DokuWiki is text-based tool allowing users to create tables and format text in different ways.
 +Even with extensive text formatting [[wp>A_picture_is_worth_a_thousand_words|one image is worth more than thousand words]]. 
 +Images are even more important for engineers and scientists. Even small images make text much more attractive and easy to focus on.
 +
 +===== SVG vs raster =====
 +==== Raster ====
 +
 +Naturally DokuWiki allows user to upload raster image onto server and show it inside document. This default mechanism has some disadvantages:
 +  * Uploading images involves extra effort from the user.
 +  * Images have size much bigger than text.
 +  * Raster images cannot be scaled because of lose of quality.
 +  * Raster images cannot be easily edited.
 +
 +==== SVG ====
 +[[wp>Scalable_Vector_Graphics|SVG]] is relatively new standard (2006) but most commonly used modern web browsers support it. SVG files are based on XML and can be embedded directly into HTML.
 +Below I show few steps/advices on how to create and them embed image into doku wiki page.
 +
 +
 +===== Steps =====
 +
 +==== Preparation ====
 +This small article does not cover creation of images itself. I recommend using [[http://www.inkscape.org|Inkscape]].
 +There are numerous tutorials available on how to use Inkscape.
 +
 +==== Size ====
 +Image should not be too big nor too small. Images in one page should look similar.
 +The default maximum width of DokuWiki template is 746 [px]. Left and right padding is 28 [px]. I assume usable width as 715 [px] This should reflect on your SVG image size. User can set Inkscape document size by clicking __File__ → __Document Properties__ under __Custom size__.
 +
 +
 +=== Oversized ===
 +<html>
 +<?xml version="1.0" encoding="UTF-8" standalone="no"?> <!-- Created with Inkscape (http://www.inkscape.org/) -->  <svg    xmlns:dc="http://purl.org/dc/elements/1.1/"    xmlns:cc="http://creativecommons.org/ns#"    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"    xmlns:svg="http://www.w3.org/2000/svg"    xmlns="http://www.w3.org/2000/svg"    xmlns:xlink="http://www.w3.org/1999/xlink"    version="1.1"    width="746"    height="400"    id="svg2">   <defs      id="defs4">     <linearGradient        id="linearGradient3882-4">       <stop          id="stop3892"          style="stop-color:#000000;stop-opacity:1"          offset="0" />       <stop          id="stop3894"          style="stop-color:#b42ded;stop-opacity:1"          offset="1" />     </linearGradient>     <linearGradient        x1="210.13885"        y1="390.96078"        x2="251.98239"        y2="185.09392"        id="linearGradient3888"        xlink:href="#linearGradient3882-4"        gradientUnits="userSpaceOnUse" />   </defs>   <metadata      id="metadata7">     <rdf:RDF>       <cc:Work          rdf:about="">         <dc:format>image/svg+xml</dc:format>         <dc:type            rdf:resource="http://purl.org/dc/dcmitype/StillImage" />         <dc:title></dc:title>       </cc:Work>     </rdf:RDF>   </metadata>   <     transform="translate(0,-652.3608)"      id="layer1">     <       transform="translate(1.8984501,-8.2676943)"        id="g3863">       <path          d="m 222.64151,293.87161 c 1.79742,3.78403 -4.21402,4.28979 -6.28931,2.98742 -5.62391,-3.52932 -3.82159,-11.70039 0.31447,-15.56603 7.39843,-6.91474 19.13114,-3.85725 24.84276,3.61635 8.38204,10.96779 3.93162,26.67631 -6.91823,34.11949 -14.46115,9.9206 -34.26388,4.02476 -43.39623,-10.22012 -11.49212,-17.92572 -4.12805,-41.87209 13.52201,-52.67295 21.37658,-13.0813 49.49202,-4.23732 61.94969,16.82389 14.68092,24.81991 4.35034,57.11926 -20.12578,71.22642 -28.25866,16.28726 -64.7514,4.46588 -80.50315,-23.42767 -17.89814,-31.69442 -4.58317,-72.38695 26.72955,-89.77988 35.12814,-19.51224 80.025,-4.70173 99.05661,30.03144 21.12869,38.5604 4.82123,87.66492 -33.33333,108.33334"          transform="translate(-1.9581529,557.78192)"          id="path3850"          style="fill:none;stroke:#cccccc;stroke-width:11.62204742;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />       <path          d="m 222.64151,293.87161 c 1.79742,3.78403 -4.21402,4.28979 -6.28931,2.98742 -5.62391,-3.52932 -3.82159,-11.70039 0.31447,-15.56603 7.39843,-6.91474 19.13114,-3.85725 24.84276,3.61635 8.38204,10.96779 3.93162,26.67631 -6.91823,34.11949 -14.46115,9.9206 -34.26388,4.02476 -43.39623,-10.22012 -11.49212,-17.92572 -4.12805,-41.87209 13.52201,-52.67295 21.37658,-13.0813 49.49202,-4.23732 61.94969,16.82389 14.68092,24.81991 4.35034,57.11926 -20.12578,71.22642 -28.25866,16.28726 -64.7514,4.46588 -80.50315,-23.42767 -17.89814,-31.69442 -4.58317,-72.38695 26.72955,-89.77988 35.12814,-19.51224 80.025,-4.70173 99.05661,30.03144 21.12869,38.5604 4.82123,87.66492 -33.33333,108.33334"          transform="translate(-7.9581525,549.78192)"          id="path3846"          style="fill:none;stroke:url(#linearGradient3888);stroke-width:11.62204742;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />       <rect          width="738.11664"          height="281.58121"          x="2.0432308"          y="719.83789"          id="rect3848"          style="fill:#ffff00;fill-opacity:0;fill-rule:evenodd;stroke:#000000;stroke-width:1.88334501" />       <text          x="93.746895"          y="911.67804"          transform="matrix(0.96032664,-0.27887764,0.27887764,0.96032664,0,0)"          id="text3852"          xml:space="preserve"          style="font-size:40px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:sans-serif"><tspan            x="93.746895"            y="911.67804"            id="tspan3854"            style="font-size:30px;font-family:Courier New;-inkscape-font-specification:Courier New">Text inside <tspan    id="tspan3872"    style="fill:#ff6600">SVG</tspan> 24</tspan></text>       <text          x="724.52075"          y="930.22076"          transform="matrix(1,0,-0.42782798,1,0,0)"          id="text3856"          xml:space="preserve"          style="font-size:40px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:sans-serif"><tspan            x="724.52075"            y="930.22076"            id="tspan3858"            style="font-family:Arial black;-inkscape-font-specification:Arial black"><tspan    id="tspan3860"    style="fill:#0000ff">Another</tspan> t<tspan    id="tspan3868"    style="fill:#808000">e</tspan><tspan    id="tspan3864"    style="fill:#800000">x</tspan>t 32</tspan></text>       <text          x="29.728065"          y="277.03772"          transform="translate(0,698.03016)"          id="text3858"          xml:space="preserve"          style="font-size:40px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:sans-serif"><tspan            x="29.728065"            y="277.03772"            id="tspan3861"            style="font-size:15px;font-family:Arial;-inkscape-font-specification:Arial">Box size: 740 x 283 [px] centered inside 746 x 400 [px] document</tspan></text>     </g>   </g> </svg> 
 +</html>
 +=== Normal size ===
 +<html>
 +<?xml version="1.0" encoding="UTF-8" standalone="no"?> <!-- Created with Inkscape (http://www.inkscape.org/) -->  <svg    xmlns:dc="http://purl.org/dc/elements/1.1/"    xmlns:cc="http://creativecommons.org/ns#"    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"    xmlns:svg="http://www.w3.org/2000/svg"    xmlns="http://www.w3.org/2000/svg"    xmlns:xlink="http://www.w3.org/1999/xlink"    version="1.1"    width="690"    height="300"    id="svg2">   <defs      id="defs4">     <linearGradient        id="linearGradient3882-4">       <stop          id="stop3892"          style="stop-color:#000000;stop-opacity:1"          offset="0" />       <stop          id="stop3894"          style="stop-color:#b42ded;stop-opacity:1"          offset="1" />     </linearGradient>     <linearGradient        x1="210.13885"        y1="390.96078"        x2="251.98239"        y2="185.09392"        id="linearGradient3888"        xlink:href="#linearGradient3882-4"        gradientUnits="userSpaceOnUse" />   </defs>   <metadata      id="metadata7">     <rdf:RDF>       <cc:Work          rdf:about="">         <dc:format>image/svg+xml</dc:format>         <dc:type            rdf:resource="http://purl.org/dc/dcmitype/StillImage" />         <dc:title></dc:title>       </cc:Work>     </rdf:RDF>   </metadata>   <     transform="translate(0,-752.3608)"      id="layer1">     <       transform="translate(1.8984501,-8.2676943)"        id="g3863">       <         transform="matrix(0.97179345,0,0,1.0000902,-0.45560122,58.190841)"          id="g3878">         <           transform="translate(-2.5725686,-3.8967658e-5)"            id="g3893">           <path              d="m 222.64151,293.87161 c 1.79742,3.78403 -4.21402,4.28979 -6.28931,2.98742 -5.62391,-3.52932 -3.82159,-11.70039 0.31447,-15.56603 7.39843,-6.91474 19.13114,-3.85725 24.84276,3.61635 8.38204,10.96779 3.93162,26.67631 -6.91823,34.11949 -14.46115,9.9206 -34.26388,4.02476 -43.39623,-10.22012 -11.49212,-17.92572 -4.12805,-41.87209 13.52201,-52.67295 21.37658,-13.0813 49.49202,-4.23732 61.94969,16.82389 14.68092,24.81991 4.35034,57.11926 -20.12578,71.22642 -28.25866,16.28726 -64.7514,4.46588 -80.50315,-23.42767 -17.89814,-31.69442 -4.58317,-72.38695 26.72955,-89.77988 35.12814,-19.51224 80.025,-4.70173 99.05661,30.03144 21.12869,38.5604 4.82123,87.66492 -33.33333,108.33334"              transform="translate(-1.9581529,557.78192)"              id="path3850"              style="fill:none;stroke:#cccccc;stroke-width:11.62204742;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />           <path              d="m 222.64151,293.87161 c 1.79742,3.78403 -4.21402,4.28979 -6.28931,2.98742 -5.62391,-3.52932 -3.82159,-11.70039 0.31447,-15.56603 7.39843,-6.91474 19.13114,-3.85725 24.84276,3.61635 8.38204,10.96779 3.93162,26.67631 -6.91823,34.11949 -14.46115,9.9206 -34.26388,4.02476 -43.39623,-10.22012 -11.49212,-17.92572 -4.12805,-41.87209 13.52201,-52.67295 21.37658,-13.0813 49.49202,-4.23732 61.94969,16.82389 14.68092,24.81991 4.35034,57.11926 -20.12578,71.22642 -28.25866,16.28726 -64.7514,4.46588 -80.50315,-23.42767 -17.89814,-31.69442 -4.58317,-72.38695 26.72955,-89.77988 35.12814,-19.51224 80.025,-4.70173 99.05661,30.03144 21.12869,38.5604 4.82123,87.66492 -33.33333,108.33334"              transform="translate(-7.9581525,549.78192)"              id="path3846"              style="fill:none;stroke:url(#linearGradient3888);stroke-width:11.62204742;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />           <rect              width="708.10199"              height="298.10199"              x="2.0505579"              y="703.30981"              id="rect3848"              style="fill:#ffff00;fill-opacity:0;fill-rule:evenodd;stroke:#000000;stroke-width:1.89799869" />           <text              x="93.746895"              y="911.67804"              transform="matrix(0.96032664,-0.27887764,0.27887764,0.96032664,0,0)"              id="text3852"              xml:space="preserve"              style="font-size:40px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:sans-serif"><tspan                x="93.746895"                y="911.67804"                id="tspan3854"                style="font-size:30px;font-family:Courier New;-inkscape-font-specification:Courier New">Text inside <tspan    id="tspan3872"    style="fill:#ff6600">SVG</tspan> 24</tspan></text>           <text              x="724.52075"              y="930.22076"              transform="matrix(1,0,-0.42782798,1,0,0)"              id="text3856"              xml:space="preserve"              style="font-size:40px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:sans-serif"><tspan                x="724.52075"                y="930.22076"                id="tspan3858"                style="font-family:Arial black;-inkscape-font-specification:Arial black"><tspan    id="tspan3860"    style="fill:#0000ff">Another</tspan> t<tspan    id="tspan3868"    style="fill:#808000">e</tspan><tspan    id="tspan3864"    style="fill:#800000">x</tspan>t 32</tspan></text>           <text              x="29.728065"              y="277.03772"              transform="translate(0,698.03016)"              id="text3858"              xml:space="preserve"              style="font-size:40px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:sans-serif"><tspan                x="29.728065"                y="277.03772"                id="tspan3861"                style="font-size:15px;font-family:Arial;-inkscape-font-specification:Arial">Box size: 690 x 300 [px] centered inside 690 x 300 [px] document</tspan></text>         </g>       </g>     </g>   </g> </svg>
 +</html>
 +Tip: In the Inkscape's __Document Properties__ user can fit document size onto objects size plus custom margins.
 +
 +==== Clean SVG ====
 +Instead saving file as SVG in Inkscape I save it as Clean SVG to remove all unnecessary code reducing size.
 +
 +==== Single line SVG ====
 +I found very usefull to join all lines of SVG file. This way DokuWiki code is much more readable. I am doing it using [[http://notepad-plus-plus.org/|Notepad++]] and key combination ''Ctrl+J'' (followed by ''Ctrl+C'').
 +
 +==== Single spaces ====
 +Notepad++ can also replace double spaces with single ones. Select __Search__ --> __Replace__ and type in __Find what__ field ''([\s]+)([\s]+)''. In the __Replace with__ field put space. 
 +Be sure that in __Search Mode__ box __Regular expression__ is selected. Finally press __Replace All__.
 +==== Embedding in DokuWiki ====
 +Method I propose does not depend on any plugins. The SVG is embedded directly into HTML.
 +
 +<code>
 +<html>
 +<svg> ... </svg>
 +</html>
 +</code>
 +
 +
 +===== Notes =====
 +
 +  * Use only [[http://www.w3schools.com/cssref/css_websafe_fonts.asp|web safe fonts]]
 +  * SVG cannot be copied just like raster images
 +  * SVG text can be copied
 +  * SVG can be extracted from HTML, re-used, re-edited
 +  * SVG will look different on different browsers due to different render engines
 +  * SVG will look good on print
 +  * SVG code can be bigger than raster code
projects/svg_dw.txt · Last modified: 2013/05/26 22:05 by mkucia