Skip to content

Instantly share code, notes, and snippets.

@StarJade-Park
Last active July 11, 2017 06:46
Show Gist options
  • Save StarJade-Park/fc372af8b8961d5f5277913e0aa9d8d0 to your computer and use it in GitHub Desktop.
Save StarJade-Park/fc372af8b8961d5f5277913e0aa9d8d0 to your computer and use it in GitHub Desktop.
[Image Rename] Convert non-order image files to order image files #python3 #image
from PIL import Image
import os
print("현재 위치 = " + os.curdir)
old_dir = os.listdir(os.path.join('.', 'old')
rename_dir = os.path.join('.', 'rename')
if not os.path.exists(rename_dir):
os.mkdir(rename_dir)
print("Make dir 'rename'")
# just need sort
new_file_list = sorted(fileList)
# select specific name of list
specific_name = 'here your input'
new_file_list = list()
for index in fileList:
if specific_name in index:
new_file_list.append(index)
rangeOfFile = range(len(new_file_list))
intToStr_ROF = map(str, rangeOfFile)
save_file_list = zip(new_file_list, list(intToStr_ROF))
for file, index in save_file_list:
image_path = os.path.join(old_dir, file)
print("File open " + image_path)
im = Image.open(image_path, 'r')
# if you need open RGBA like .png files
im = im.convert('RGB')
print("Save rename image in 'rename' folder, rename = " + index + ".jpg")
im.save(os.path.join(rename_dir, (index + ".jpg")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment