You can scale SVG files without losing image quality. That is why this file format is heavily used for logos and icons. In some cases, you do need to convert SVG to other image file format for compatability with printing apps. So, we will learn how to change SVG to PNG in Python using Aspose.CAD for Python via .NET. This 3D CAD SDK helps in achieving automation of file format conversion for single as well as multiple files. We will write a complete code sample to demonstrate the usability and efficiency of Aspose.CAD for Python via .NET.
3D CAD SDK Installation
Aspose.CAD for Python via .NET specializes in the processing of CAD drawings. However, it comes with an easy installation procedure. Simply download the SDK files or run the following command in CMD:
pip install aspose-cad
Change SVG to PNG in Python - Code Sample
In addition to conversion features, this powerful SDK also enables you to choose a specific layer and track the conversion process. So, let’s jump to the code steps and the code sample now.
Steps:
- Load an SVG file from the given input path by calling the load method.
- Configure rasterization options for converting vector to raster.
- Set output image width, height and zoom level.
- Create an object of the PngOptions class.
- Save the loaded CAD image as a PNG using the configured rasterization.
Change SVG to PNG in Python by using the code snippet given below:
Output:
Have a Question?
You may ask your questions on our forum.
SVG to PNG - Get a Free License
Get a free temporary license to try Aspose.CAD for Python via .NET.
Final Thoughts
With a few lines of code, you can develop an SVG to PNG converter for your application. We have gone through the impementation process that how can we change the SVG to PNG in Python programmatically. Aspose.CAD for Python via .NET is super straight and you can easily configure the flow as per your needs. In addition, we highly recommend you to visit the documentation and API refs. We have also published code examples at our GitHub repo.
FAQs
Q: How to convert SVG to PNG programmatically?
A: Aspose.CAD for Python via .NET offers a complete solution for SVG to PNG conversion in multiple programming languages. For the solution in Python, please visit this link.
Q: Can I try Aspose.CAD for Python for free?
A: Yes, you can obtain a free temporary license to try the features.