Convert SVG to Image – Use Cloud SDK and REST API

SVG to Image

Converting SVG to image formats such as PNG or JPEG ensures compatibility with all devices and software, as these formats are supported everywhere. For example, tools such as Adobe Photoshop are optimized to work with formats such as PNG, JPEG, or TIFF. Additionally, raster images are often required for certain purposes, such as social media posts or email attachments, where vector formats may not be supported.

Aspose.HTML Cloud v4.0 provides the simplest API to convert SVG documents to Image file formats with high quality, easy and fast.

The article explains in a set of code examples how to convert an SVG document to Image file formats such as JPEG, PNG, GIF, TIFF or BMP using Aspose.HTML Cloud SDKs and REST API calls. SDKs are available in PHP, C++, Python, C#, Ruby, Java, Android, Swift, and Node.js.

SDK Examples of SVG to Image Conversion

A common use case for Aspose.HTML Cloud SDK functions is file processing and conversion. The Cloud SDK enables you to retrieve an SVG document from storage by its name or from a local file on your drive, convert it to a specified format, and save it back to storage or your local drive. The following code examples demonstrate how to convert SVG to Image using various SDKs and cURL for different scenarios.

Example 1. Convert SVG to JPG

JPG is one of the most commonly used image formats due to its controlled quality loss during compression. This makes it ideal for storing and sharing graphic content such as photos, scanned copies, and digitized images over the Internet. Here’s an example of converting a local SVG file to JPG format and saving the result to a local file system using default conversion options.

SVG to JPG conversion occurs with the default conversion options: the resulting JPG document’s width and height correspond to A4, and all margins have zero value.

Example 2. Convert SVG to PNG with explicitly specified options

The PNG image format is widely used for transmitting pictures over the network, displaying photos and graphics on web pages, and storing images in cloud storage. PNG supports transparency and is optimized for the web. Converting SVG to PNG provides broad compatibility across platforms and applications, making it easier to display and share images. The example below demonstrates how to convert an SVG to PNG with explicitly specified options and save the result to a local file system.

More details about available conversion parameters for SVG files are in the SDK Conversion Options section.

Example 3. Convert SVG to GIF inside cloud storage

Aspose.HTML Cloud enables you to retrieve an SVG file from your cloud storage and save the converted result back to the cloud, using default conversion options.

GIF images are widely supported across platforms, devices, and web browsers, ensuring consistent display and user accessibility. Converting SVG to GIF can simplify the graphic, making it more accessible for various applications that may not fully support SVG.

See Also