-
Notifications
You must be signed in to change notification settings - Fork 0
/
image.py
executable file
·23 lines (22 loc) · 968 Bytes
/
image.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env python3
import shutil
import os,sys
from PIL import Image
import subprocess
folder = '/home/user/images' #folder that has the images
new_folder = '/home/user/imaged' #folder the images will be copied to
ds = '/home/user/imaged/.DS_Store'
#iterate over the files in the folder variable
for filename in os.listdir(folder):
full_filename = os.path.join(folder,filename)
if os.path.isfile(full_filename):
shutil.copy(full_filename, new_folder) #copy the files to the new folder
# when copying the files a .DS_store file is created, delete it.
subprocess.run(["rm",ds])
#iterate over the files in the new_folder variable
for files in os.listdir(new_folder):
full_file = os.path.join(new_folder,files)
if os.path.isfile(full_file):
img = Image.open(full_file).rotate(270).resize((128,128)) #rotate thand resize the files
img = img.convert('RGB') #convert the files
img.save(full_file, 'jpeg') #save the files