XML technologies / SVG / Adding hyperlinks and external files / Including external files / Using complete external graphics

(Excerpt from “Das Einsteigerseminar SVG — Webgrafiken mit XML” by Helma Spona)

Include external graphics of any supported format with the <image> tag, specifying the file with the attribute xlink:href. The next example incorporates a PNG image into a fill pattern, used to fill lettering and a rectangle.

Besides the external image’s name, specify its width and height with the attributes width and height. Omitting them sets width and height to 0, so the image is not displayed.

<?xml version="1.0" standalone="no"?>
...
<svg width="1000" height="800">
  <defs>
    <pattern id="hintergrund" patternUnits="userSpaceOnUse" x="0" y="0" width="600" height="434">
      <image xlink:href="feuer.png" width="600" height="434"/> 
    </pattern>
  </defs>
  <text x="10" y="150" style="fill:url(#hintergrund);stroke:none;font-family:'Arial Black';font-size:150;font-weight:bold">Feuer</text>
  <rect x="0" y="0" width="450" height="215" style="fill:url(#hintergrund);fill-opacity:0.4;stroke:orange"/>
</svg>

The result looks as follows:

Result of the fill pattern with a PNG image

Figure: Result of the fill pattern with a PNG image.

The <image> tag not only defines graphics in fill patterns but can also insert graphics directly. The following example demonstrates this by creating a list with graphic bullets.

<?xml version="1.0" standalone="no"?>
...
<svg width="1000" height="800">
  <g transform="translate(0,0)">
    <image  x="10" y="10" xlink:href="mk.png" width="32" height="24" /> 
    <text x="40" y="30" style="font-size:12px;font-family:Arial;font-weight:bold">Browser-Bugs.de</text>
  </g>
  <g transform="translate(0,30)">
    <image  x="10" y="10" xlink:href="mk.png" width="32" height="24" /> 
    <text x="40" y="30" style="font-size:12px;font-family:Arial;font-weight:bold">vmi-buch AG</text>
  </g>
  <g transform="translate(0,60)">
    <image  x="10" y="10" xlink:href="mk.png" width="32" height="24" /> 
    <text x="40" y="30" style="font-size:12px;font-family:Arial;font-weight:bold">Die Webseite zum Buch</text>
  </g>
  <g transform="translate(0,90)">
    <image  x="10" y="10" xlink:href="mk.png" width="32" height="24" /> 
    <text x="40" y="30" style="font-size:12px;font-family:Arial;font-weight:bold">Meine Webseite</text>
  </g>
</svg>

This list is the result.

External graphics as list bullets

Figure: External graphics as list bullets.

   

 

 

 

back to top