Convert SVG to SVGZ in C# – Understanding SVGZ Format

Scalable Vector Graphics (SVG) is a widely used format for web graphics and vector illustrations. However, SVG files can be large, which can impact your site’s loading time and performance. To optimize file size, you can use the SVGZ format, a compressed version of SVG that uses Gzip.

This article covers how to transform an SVG file to SVGZ using Aspose.SVG for .NET.

What is an SVGZ File Format?

An SVGZ file is an SVG file compressed with Gzip compression. It uses a lossless data compression algorithm and contains graphic data in XML format, including the positioning of shapes, text, curves, lines, and colors that make up the 2D graphics. SVGZ files also support layers, transparency, gradients, filters, and animation. Modern browsers and applications support it natively as long as the server is configured correctly. SVGZ files can be opened and edited in any application that supports the SVG format, such as Adobe Illustrator, Corel Draw, and Inkscape.

SVGZ format was developed by the World Wide Web Consortium (W3C) and first released in 2001 as an alternative to the SVG file format. What sets SVGZ files apart from SVG files is their size. They are typically 50 to 70 percent smaller than the uncompressed version. This is especially useful for web applications and digital assets, i.e., when transferring SVG graphics online.

Save SVG Document as SVGZ

Aspose.SVG for .NET API offers the Aspose.Svg.Saving namespace is presented by API entities for a description of specific save options at the conversion/saving process. For example, the SVGSaveFormat enumeration specifies the format in which the document is saved, and you can select an SVGZ format. Follow these steps:

The following code snippet can be used to convert an SVG file to SVGZ format:

1using Aspose.Svg.Saving;
2using System.IO;
3...
4
5    // Load an SVG document
6	SVGDocument document = new SVGDocument(Path.Combine(DataDir, "shapes.svg"));
7	
8	// Save the document as SVGZ
9	document.Save(Path.Combine(OutputDir, "shapes.svgz"), SVGSaveFormat.SVGZ);

What is Gzip?

Gzip is software (utility or technology) used for lossless data compression and decompression and associated compressed data format used by the utility. Originally created by Jean-loup Gailly and Mark Adler in 1992, Gzip efficiently reduces file sizes while preserving data integrity. The Gzip utility and format remain widely used many years later.

Gzip Compression Technology

Gzip (GNU zip) is a popular compression technology for reducing the size of files (mostly text files) so that they can be transferred faster over the Internet. Gzip implements lossless data compression using the DEFLATE algorithm. It is widely used in web development, software distribution, and data storage to improve efficiency. Website owners enable GZIP compression on their servers to speed up page loading and make visitors happier.

Why Do We Use GZIP Compression?

The key advantage of Gzip compression is faster page loading by reducing file sizes. According to Google, delaying page load times from one to three seconds can increase bounce rates by 32%, meaning a significant audience loss due to a small delay.

Gzip compression provides a balance between efficiency and speed, reducing data size by up to 70% with minimal computing resources. Although Gzip is not the most efficient in terms of compression ratio, it is significantly faster than other methods, making it ideal for web data transfers where speed is critical. Its low resource consumption further enhances its suitability for optimizing website performance.

Conclusions

  1. SVGZ files support all SVG features, including interactivity, animation, and CSS styling.
  2. Since SVG files can be large due to their XML-based structure, compressing them with Gzip to SVGZ significantly reduces their size, resulting in faster loading.
  3. SVGZ files can be opened in vector-based graphics editing programs, such as Adobe Illustrator or Inkscape, to be edited or resized.
  4. Many modern web browsers and applications support SVGZ, making it useful for web graphics.

See also

Aspose.SVG offers a free online SVG Converter for converting SVG files to a variety of popular formats. You can easily convert SVG to PDF, SVG to XPS, SVG to JPG, SVG to PNG, SVG to BMP, SVG to TIFF, SVG to GIF. Just select a file, choose the format to convert, and you’re done. It’s fast and completely free!

Text “SVG Converter”

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.