Batch Image editor using Python

Published on . Written by

Batch Image Editor using Python

If we want to modify (resize, change file format, etc.) a single image. It is an easy job, just open a favorite image editor and do the modification. But what if you want to modify hundreds and hundreds of such images? It not only becomes time-consuming and boring also.

Read more..

SLNOTE

Skyfi Labs Projects
This is the place where Python and the Python Imaging Library (PIL) comes into play. By making use of python script you can process images in bulk.

In this project, we are going to create a small Python script that will allow us to resize, crop, blur or convert images into greyscale on a large scale.

Project Description

The objective of this project is to modify the images on a large scale at a time without manual intervention. So, by using the python script and PIL library we will build the project.

In this project, we have to specify the path of the directory where all images are stored, at the time of compilation as a command-line argument. Suppose project name is project_name.py, then at execution time write command like python3 project_name.py path/to_directory/where/images_are_stored/*.png

Then a prompt will ask which operation to perform, like 1 for resizing, 2 for cropping, 3 for blurring and so on. Give a proper input then you will get the modified image.

Python Modules used for projects:

sys: sys-module is used to provide access to some variables used or maintained by the interpreter and to functions that interact strongly with the interpreter. We are going to use sys.argv to list out the command line arguments passed to Python script. The argument that we passed in the command line is the path of the directory where all images reside.


SLLATEST
Python Imaging Library (PIL): PIL offers many standard procedures for image manipulation such as pre-pixel manipulation, image filtering, blurring, contouring, smoothing or edge detection, adding text to images and much more. It is also used to load images from the hard drives and display the image.

OS – Module: os–module provides all the functionalities of interacting with the operating system. OS-module provides an easy way of interacting with os dependent functionalities. It is distributed under Python standard utility library.

Project Implementation

Follow the below steps to complete the project:

  • Loop through all the images one by one. Ask the user to give what modification to perform on the image.
  • While executing the script give the path of the directory where images are stored. (to process all the images, give path like /path/todirecory/ * .jpeg)
  • According to the choice of the user, modify the image using PIL library methods.
  • Using the os module split the filename into name and extension and store it in two variables.
  • Save those newly generated images with some modified names (like oldname+ ‘_edited.png’)
  • When all images are done loop will terminate and you are done with your work.
Software requirements: Text editor and Python3.

Programming Languages and module: Python, PIL-module, os module, sys-module.


SLDYK
Kit required to develop Batch Image editor using Python:
Technologies you will learn by working on Batch Image editor using Python:


Any Questions?


Subscribe for more project ideas