Lädt...

🔧 SVG essentials. Introduction


Nachrichtenbereich: 🔧 Programmierung
🔗 Quelle: dev.to

SVG is an XML-based markup language that stands for Scalable Vector Graphics. As the name suggests, images in SVG format are defined by mathematical formulas, not by grids and pixels (in contrast to raster graphics). It makes SVG format ideal for icons, logos and line drawings:

  • they can resize without loss of quality,
  • the file size is much smaller than for raster graphics.

Furthermore, we can target elements in an SVG to change their presentation with CSS - fit color to our primary one, add some animation and more! If you need vector images on web, isn't it the best image format?

Table of contents

  1. SVG in HTML document
  2. SVG as XML language
  3. SVG image structure

SVG in HTML document

There are several ways to display an SVG image on a webpage:

  • directly embedded (inlining SVG):
<html>
  <head>
  </head>
  <body>
    <svg>
    </svg>
  </body>
</html>

We can manipulate this SVG image with JavaScript and CSS. However, the browser can't cache inline SVG.

  • using img element:
<img src="flower.svg" alt="flower" />

We can't control the SVG image with JavaScript. CSS works only inside SVG code. The browser caches the image.

  • using object element:
<object data="flower.svg" type="image/svg+xml"></object>

It has similar fallbacks as in with img element

  • using iframe element:
<iframe src="flower.svg"></iframe>

Since we can open SVG image in the browser as it is, we can embed SVG file in iframe. However, every iframe requires more memory and other computing resources.

SVG as XML language

There are main rules for SVG code since it's XML language (that may differ from HTML):

  • case-sensitivity,
  • closing tags,
  • attribute values are in quotation marks (single or double).

SVG image structure

For instance, you got the SVG image created in graphic design software:

Let's analyze the code line by line.

<?xml version="1.0" encoding="UTF-8"?>

The first line identifies file as XML. It's not necessary for SVGs, used in web, unless encoding is other than UTF-8.

<svg
 xmlns="http://www.w3.org/2000/svg"
 viewBox="0 0 100 100"
>
...
</svg>
  • It's SVG root element. All drawing happens inside this element.
  • xlmns attribute declares XML namespace: the link to svg tells the browser that this document uses vocabulary defined in SVG.
  • viewBox defines a drawing region in abstract units characterized by:
    • an origin min-x min-y. In our example, it's 0 0,
    • a size (width, height). Here, it's 100 100.
    • All shapes and lines are drawn in respect to this drawing region.
  • width and height can be set inside svg tag: width="100" height="100" that means image has 100px as width and height.
<defs>
...
</defs>

defs element defines style or elements, that will be referenced later. In this example, defs contains style element that is familiar from html structure. However, it can also define shapes, gradients, symbols.

<defs>
<style>
    .d {
        fill: #d2693a;
    }

    .d,
    .e {
        stroke: #000;
    }

    .e {
        fill: #8fcc93;
    }
</style>
</defs>

It must look similar for CSS users, there are classes with properties: fill is like background-color for SVG element, stroke is border-color.

<g>
...
</g>

This tag groups different objects. In Adobe Illustrator each layer transforms into <g> element on export as SVG.

<g>
<path class="d" d="M44.11,53.83s23,33.9,0,33.9,0-33.9,0-33.9Z" />
...
<circle class="e" cx="44.11" cy="44.11" r="14.5" />
</g>

Finally, some actual drawing: path is used for more complicated objects, while circle, rect, line, ellipse, polygon are basic shapes. Since SVG is XML language, it's required to close all tags and we see that there's / before closing bracket in circle and path.

...

🕵️ Artifex MuPDF 1.14.0 svg/svg-run.c fz_xml_att SVG File denial of service


📈 33.05 Punkte
🕵️ Sicherheitslücken

🔧 SVG essentials. Introduction


📈 30.11 Punkte
🔧 Programmierung

📰 How Do the Cyber Essentials and Cyber Essentials Plus Assessments Work?


📈 22.5 Punkte
📰 IT Security Nachrichten

🔧 SVG essentials. Embedded image and filter effects


📈 22.27 Punkte
🔧 Programmierung

🔧 SVG essentials. Gradients and patterns


📈 22.27 Punkte
🔧 Programmierung

🔧 SVG essentials. Basic shapes and path


📈 22.27 Punkte
🔧 Programmierung

🔧 Contextual SVG fill and stroke values - simplify theming with SVG


📈 22.04 Punkte
🔧 Programmierung

🕵️ CVE-2019-18853 | ImageMagick up to 7.0.8 SVG coders/svg.c input validation


📈 22.04 Punkte
🕵️ Sicherheitslücken

🕵️ CVE-2023-50251 | dompdf php-svg-lib up to 0.5.0 SVG File recursion


📈 22.04 Punkte
🕵️ Sicherheitslücken

🕵️ CVE-2023-50252 | dompdf php-svg-lib up to 0.5.0 SVG File unknown vulnerability


📈 22.04 Punkte
🕵️ Sicherheitslücken

🕵️ Medium CVE-2022-0863: Wp svg icons project Wp svg icons


📈 22.04 Punkte
🕵️ Sicherheitslücken

🐧 Oh My SVG: reduce the size of SVG


📈 22.04 Punkte
🐧 Linux Tipps

🕵️ scratch-svg-renderer up to 0.1.x SVG _transformMeasurements cross site scripting


📈 22.04 Punkte
🕵️ Sicherheitslücken

🕵️ CVE-2024-11184 | wp-enable-svg Plugin up to 0.7 on WordPress SVG File cross site scripting


📈 22.04 Punkte
🕵️ Sicherheitslücken

🕵️ Artifex MuPDF 1.14.0 svg/svg-run.c svg_run_image href_att denial of service


📈 22.04 Punkte
🕵️ Sicherheitslücken

🕵️ ImageMagick 7.0.8-13 SVG Image File coders/svg.c SVGStripString memory corruption


📈 22.04 Punkte
🕵️ Sicherheitslücken

📰 safe-svg SVG validator to prevent XSS


📈 22.04 Punkte
📰 IT Security Nachrichten

🔧 Introduction to Message Brokers: Kafka essentials


📈 19.09 Punkte
🔧 Programmierung

🎥 Linux Essentials For Hackers - #1 - Introduction


📈 19.09 Punkte
🎥 IT Security Video

matomo