-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathimage_resizing.py
49 lines (38 loc) · 1.32 KB
/
image_resizing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import os
from PIL import Image
"""
1. Open up the folder of images (get the latest folder somehow?)
2. Loop through the folder (use a counter to keep track of image position)
- Create blank paper-sized image (if one isn't created already)
- Grab image
- Determine whether the image needs to be rotated correctly
- Rotate if needed
- Add to paper (even: top, odd: bottom)
This script is meant to be moved into the created folder - probably should be
rewritten to always search the latest created folder.
"""
#for i, row in enumerate(csv_rows):
current_dir = os.path.dirname(os.path.abspath(__file__))
items = os.listdir(current_dir)
counter = 0
for item in items:
try:
im = Image.open(item)
except IOError:
#print "Not an image"
continue
# if item's width is 1200, means it's a vertical image that needs to be rotated
if im.size[0] == 1200:
im = im.rotate(90)
# if iteration is even, put the image at the top of the blank file
#print counter
if counter % 2 == 0:
empty = Image.open("../../blank.jpg")
empty.paste(im, (300,200))
else:
empty.paste(im, (300,1900))
save_name = "created-%s.jpeg" % counter
empty.save(save_name)
counter += 1
save_name = "created-%s.jpeg" % counter
empty.save(save_name, quality=95)