import os
import glob
from PIL import Image

i = 0
dstPath = 'd:/output/comp/'
srcPath = 'd:/input/'


globPath = os.path.join(srcPath,'**')
searchResult = glob.glob(globPath, recursive=True)

for file in searchResult:
    if os.path.isfile(file):
        if os.path.splitext(file)[1] in ['.JPG','.jpg']:
            i+=1
            srcPath = os.path.relpath(file)
            im = Image.open(file)
            im.save(os.path.join(dstPath,srcPath)