-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeneral_crop.py
42 lines (32 loc) · 1.1 KB
/
general_crop.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#from PIL import Image
from PIL import Image, ImageOps
import os, sys
import cv2
import sys
import math
import numpy as np
import glob
from progressbar import ProgressBar
pbar = ProgressBar()
def resizeImage(infile, output_dir="resized"):
outfile = os.path.splitext(infile)[0]+"_resized"
extension = os.path.splitext(infile)[1]
if (infile != outfile and infile!= "croppedpicpp.PNG"):
try :
#opening image in numpy
im = Image.open(infile)
imageW,imageH = im.size
size=(300,300)
im = ImageOps.fit(im, size, method=0, bleed=0.0, centering=(0.5, 0.5))
path = output_dir
filename = os.path.join(path, outfile)
im.save(filename + outfile + ".PNG")
except IOError:
print ("cannot reduce image for ", infile)
if __name__=="__main__":
output_dir = "resized"
dir = os.getcwd()
if not os.path.exists(os.path.join(dir,output_dir)):
os.mkdir(output_dir)
for file in pbar(os.listdir(dir)):
resizeImage(file,output_dir)