

PIL for Image Processing and glob for iterating through files of the given folder in the OS. This section just imports the required packages. Lines 1 and 2: from PIL import Image # Python Image Library - Image Processing import glob The save () method is used to save images. We will introduce them one by one with examples. Pillow provides 2 methods ( save () & convert () ) for us to convert between different image formats. Pillow Provided Methods To Convert Image Formats.
CONVERT IMAGE FORMAT WITH PYTHON HOW TO
CONVERT IMAGE FORMAT WITH PYTHON MANUAL
That’d definitely require more manual effort to do without coding (I know you can smell bash ing). Before your grey matter cells are rushing to judge whether I’m crazy to build this tool, let me say that this is not just for one image - but for all the images inside a folder. In this tutorial, we’re going to build an image type convertor that converts a PNG image to a JPG image. Disclaimer: The number of lines (6) excludes empty lines and comments Either way, we’re setting out here to build one such script that converts images from one file format (image type) to another - in just 6 lines of Python code.


Sometimes the word script would be more accurate. With this philosophy in place, a lot of niche tool development using Python can be done so succinctly that it makes me wonder if it’s worth calling it a tool at all. One of the points in the The Zen of Python says: Simple is better than complex. This likely makes you feel more powerful knowing a programming language - especially if that Programming language is as versatile and awesome as Python is. Unlike a non-programmer, you are probably not spending hours digging through multiple Google search result pages to find a tool that, in the first place, was supposed to improve your productivity ( irony wins). One of the advantage of being a programmer is your ability to build utility tools to improve your life. By AMR How to build an image type convertor in six lines of Python Photo by Keagan Henman on Unsplash
