This guide explains how to convert TIFF to PNG using Python. It contains all the details to set the environment, a list of steps, and a sample code for transforming TIFF into PNG using Python. It will provide details to customize the output PNG file using the respective properties and methods in the PngOptions class.
Steps to Change TIFF to PNG using Python
- Set the environment to use Aspose.Imaging for Python via .NET for TIFF to PNG conversion
- Import necessary classes from Aspose.Imaging and aspose.pycore
- Load the Sample.tiff image using Image.load()
- Cast the generic Image object to a TiffImage to access TIFF-specific properties
- Create a PngOptions object to hold PNG export settings
- Set the resolution of the PNG image to match the original TIFF resolution
- Save the image as result.png with the defined options
These steps define the process to transform the file format from TIFF to PNG using Python. Import the necessary classes and objects from the respective modules, load the source TIFF file into the image class object, change the type of the loaded image to TIFF image, declare the PNG option, and set the resolution settings. Finally, call the save method to change the loaded TIFF image to PNG with the specified configuration.
Code to Convert TIFF File to PNG using Python
The above sample code has demonstrated the process of developing a TIF to PNG converter using Python. The aspycore.as_of() method is used for type casting similar to C# and Java. Note that we have preserved the original TIFF image’s horizontal and vertical resolution while creating the PNG file. However, you may change it if required.
This article has taught us the process of changing a TIFF file to PNG. To convert a PNG to ICO, refer to the article on Convert PNG to ICO Format using Python.