SVG (.svg, .svgz)
SVG (.svg, .svgz)
Background & Context
-
- MIME type: image/svg+xml
- SVG vector graphics format.
- Intended for two-dimensional vector graphics on the web.
- Partially supported by several web browsers and browser plugins.
- SVG is an acronym for Scalable Vector Graphics.
- XML-based text format.
- Can represent static and animated graphics.
- Supports RGB color with an optional alpha channel.
- Developed by the W3C SVG Working Group since 1998.
Import & Export
- Import["file.svg"] imports an SVG file, returning a rasterized image.
- Import["file.svg",elem] imports the specified element from an SVG file.
- The import format can be specified with Import["file","SVG"] or Import["file",{"SVG",elem,…}].
- Export["file.svg",expr] exports text or vector graphics to SVG.
- Export["file.svg",expr,elem] creates an SVG file by treating expr as specifying element elem.
- The export format can be explicitly specified with the command Export["file",expr,"SVG"].
- See the following reference pages for full general information:
-
Import, Export import from or export to a file CloudImport, CloudExport import from or export to a cloud object ImportString, ExportString import from or export to a string ImportByteArray, ExportByteArray import from or export to a byte array
Import Elements
- General Import elements:
-
"Elements" list of elements and options available in this file "Rules" list of rules for all available elements "Summary" summary of properties - Data representation elements:
-
"Image" Image object representing the SVG file "Graphics" Graphics object representing the SVG file - Metadata elements:
-
"Dimensions" default width and height "XMLMetaInformation" metadata given as an XMLElement
Options
- Import options:
-
ImageResolution $ImageResolution image resolution in dpi for rasterization ImageSize Automatic final displayed image size in printer's points RasterSize Automatic raster size in pixels for rasterization
Examples
open all close allBasic Examples (3)
Import an SVG file as an image:
Import["ExampleData/spikey.svg"]Import["ExampleData/spikey.svg", "Summary"]Export vector graphics to SVG:
Graphics[{Opacity[0.5], Blue, Disk[], Yellow, Disk[{1, 0}]}]Export["disks.svg", %]Scope (5)
Import (2)
Export (3)
Export["lorem.svg", "Lorem ipsum *dolor* sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et *dolore* magna aliqua."]Export a function plot to SVG:
Export["plot.svg", [image]]Show SVG data created by the Wolfram Language:
ExportString[Graphics[{Red, Disk[]}], "SVG"]Import Elements (6)
Available Elements (1)
Data Representation (2)
"Graphics" (1)
Metadata (3)
"Dimensions" (1)
"MetaInformation" (1)
Import Options (3)
ImageResolution (1)
Import the SVG with a resolution suitable for FHD screens:
Import["ExampleData/spikey.svg", "Image", ImageResolution -> 72]//ImageDimensionsImport the SVG with a resolution suitable for HiDPI screens:
Import["ExampleData/spikey.svg", "Image", ImageResolution -> 144]//ImageDimensionsImageSize (1)
RasterSize (1)
Render a very small image from the SVG:
Import["ExampleData/spikey.svg", "Image", RasterSize -> 100]ImageDimensions[%]Render a larger image from the SVG:
Import["ExampleData/spikey.svg", "Image", "RasterSize" -> 200]ImageDimensions[%]Tech Notes
History
Introduced in 2003 (5.0) | Updated in 2007 (6.0) ▪ 2022 (13.2) ▪ 2023 (13.3)