Last active
July 31, 2019 20:47
-
-
Save ElliotFriend/807fa67cfb374ebb2992e0ad8e286f40 to your computer and use it in GitHub Desktop.
I subscribe to Grow Curriculum (https://growcurriculum.org), and they recently released (most) of the stuff for the upcoming school year. I didn't want to scale all the images manually, and created the TripleHead2Go collages myself. So, this script came into existence.
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
import sys | |
import os | |
import glob | |
from os import path | |
from PIL import Image | |
glob_pattern = 'C:/Users/evoris/Grow Curriculum/2019-2020/02 Curriculum/**/Graphics & Video/Horizontal/' | |
for graphics_dir in glob.iglob(glob_pattern, recursive=True): | |
if os.path.isdir(graphics_dir): | |
# create "scaled" directory | |
scaled_dir = graphics_dir + '/Scaled/' | |
if not os.path.isdir(scaled_dir): | |
os.mkdir(scaled_dir) | |
# start a new image for the th2g size | |
th2g_image = Image.new('RGB', (3840, 720)) | |
# walk the directory to get the image files | |
for root, dirs, files in os.walk(graphics_dir): | |
for file in files: | |
# scale and save images at 720p | |
image = Image.open(os.path.join(root, file)) | |
tn_image = image.thumbnail((1280, 1280), Image.ANTIALIAS) | |
image.save(scaled_dir + file, subsampling=0, quality=100) | |
im_subject, im_direction, im_series, im_curr = file.split('_') | |
if im_subject == 'BackgroundSlide': | |
#add it to the th2g image | |
th2g_image.paste(image, (0, 0)) | |
th2g_image.paste(image, (2560, 0)) | |
elif im_subject == 'TitleSlide': | |
th2g_image.paste(image, (1280, 0)) | |
image.close() | |
th2g_image.save(scaled_dir + 'TH2G_' + im_series + '_GrowStudents.jpg', subsampling=0, quality=100) | |
else: | |
print('Scaled directory already exists: ' + scaled_dir + ' (Skipping)') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment