How to rename and convert batch photos

Sometimes we need to rename a large number of photos for processing. If anyone tries renaming hundreds or  more photos one by one, it will take a huge time and effort. Here is a python code that will help you renaming thousands of photos with in a second.

You just have to copy all the photos to a “new folder”.  This “new folder” and the python code should in a same folder.

Run the python code & see the magic.

If you want to change the format of the photos to a particular format (ex: bmp) just change the extension name.

rename(path,’renamed_image’,0,’bmp’) … Here  i wanted to change them to .bmp  .so i wrote bmp. Just change it to jpg/jpeg as required.

import os
def rename(path,new_name,numbering,extension):
    list=os.listdir(path)
    os.chdir(path)
    try:
        count=numbering
        for i in list:
            os.rename(i,new_name+str(count)+'.'+extension)
            count+=1
    except:
          print ('error')
path="C:\Users\Desktop\Python\new folder"
rename(path,'image',1,'bmp')

N.B: The code is successfully tested in python 2.7

Discussion:

The folder which contains the images should be correctly addressed. For this,  we have to write the path,

path="C:\Users\Desktop\Python\new folder"

If you want to change the format of the photo, just change the extension.

Here  i wanted to change them to .bmp . So i renamed the extension as bmp. Just change it to jpg/jpeg as required.

rename(path,'image',1,'bmp')

Leave a Reply

Your email address will not be published. Required fields are marked *