Created
March 2, 2018 11:56
-
-
Save stevenliebregt/504f7f0be2b9880d836e20eee33996d1 to your computer and use it in GitHub Desktop.
Resize images, edit to change folders and or sizes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import os | |
from PIL import Image | |
CURRENT_PATH = os.path.dirname(os.path.abspath(__file__)) | |
INPUT_PATH = CURRENT_PATH + '/png' | |
OUTPUT_PATH = CURRENT_PATH + '/png_50' | |
TARGET_SIZE_X = 50 | |
TARGET_SIZE_Y = 50 | |
TARGET_SIZE = TARGET_SIZE_X, TARGET_SIZE_Y | |
def resize(file): | |
print('...resizing : ' + file + '...') | |
infile = INPUT_PATH + '/' + file | |
outfile = OUTPUT_PATH + '/' + file | |
im = Image.open(infile) | |
im.thumbnail(TARGET_SIZE) | |
im.save(outfile) | |
if __name__ == '__main__': | |
if not os.path.exists(INPUT_PATH): | |
print('Error, input path `png` does not exist') | |
exit(1) | |
if not os.path.exists(OUTPUT_PATH): | |
os.mkdir(OUTPUT_PATH) | |
print('Start resizing...') | |
for file in os.listdir(INPUT_PATH): | |
resize(file) | |
print('...done resizing!') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment