Let us see how to convert an image into jpg format in Python. The size of png is larger when compared to jpg format. We also know that some applications might ask for images of smaller sizes. Hence conversion from png(larger ) to jpg(smaller) is needed.
For this task we will be using the
Image.convert() method of the Pillow module.
- Import the Image module from PIL and import the os module.
- Import the image to be converted using the
- Display the size of the image before the conversion using the
- Convert the image using the
"RGB"as the parameter.
- Export the image using the
- Display the size of the image after the conversion using the
We will be converting the following image :
The size of the image before conversion : 26617 The size of the image after conversion : 18118
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course