# this script make automatic resize from 4k image.

import glob
import os
import ntpath
import PIL
from PIL import Image

images_path = os.path.join('./data','test')
output_dir = os.path.join('./data','exportResize1024')

if not os.path.isdir(output_dir):
    os.makedirs(output_dir)

files = glob.glob(os.path.join(images_path, '*'))
for index, name in enumerate(files):
    imageBaseName = ntpath.basename(name).split('.')[0]
    mywidth = 512
    img = Image.open(name)
    wpercent = (mywidth / float(img.size[0]))
    hsize = int((float(img.size[1]) * float(wpercent)))
    img = img.resize((mywidth, hsize), PIL.Image.ANTIALIAS)
    img.save(os.path.join(output_dir, imageBaseName) + '_1024' + '.jpg')