Skip to content

Instantly share code, notes, and snippets.

@cawabunga
Created May 5, 2020 07:37
Show Gist options
  • Save cawabunga/f5c0e37592deda5e789c1b46cc2e1529 to your computer and use it in GitHub Desktop.
Save cawabunga/f5c0e37592deda5e789c1b46cc2e1529 to your computer and use it in GitHub Desktop.
Qwerty
# -*- coding: utf-8 -*-
"""
Created on Tue May 5 00:38:34 2020
@author: RIbatullin
"""
def squeeze():
from tkinter.filedialog import askdirectory
import os
from PIL import Image
path = askdirectory(title='Select Folder') # shows dialog box and return the path
path2 = path + '//squeezed'
try:
os.mkdir(path2)
except OSError:
pass
for f in os.listdir(path):
if f.endswith(".JPG") or f.endswith(".JPEG"):
img = Image.open(path+'/'+ f)
new_img = img.resize((img.width,img.height//2))
exif = img.info['exif']
new_img.save(path2+'/'+f, 'JPEG', exif = exif)
if __name__=="__main__":
#import doctest
#doctest.testmod(verbose=False)
squeeze()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment