-
Notifications
You must be signed in to change notification settings - Fork 0
/
Thumbnailificator-size.py
executable file
·43 lines (35 loc) · 1.36 KB
/
Thumbnailificator-size.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
#!/usr/bin/python
from PIL import Image
from glob import glob
import os.path
import os
# Define desired sizes
listSizes = [16, 24, 32, 48, 64, 96, 128, 256]
os.chdir('./input')
listIcons = glob(r'**/*.png')
outputPath = '../output'
def main():
for iconPath in listIcons:
# splitting input path
iconType, iconName = iconPath.split('/')
for sizeItem in listSizes:
# concatenating
dirNameFormated = f'{sizeItem}x{sizeItem}'
dirNameDoubled = f'{dirNameFormated}@2x'
# output format
outputPathFormated = f'./{outputPath}/{dirNameFormated}/'
outputPathDoubled = f'./{outputPath}/{dirNameDoubled}/'
# making directories
os.makedirs(os.path.dirname(outputPathFormated), exist_ok=True)
os.makedirs(os.path.dirname(outputPathDoubled), exist_ok=True)
# image ratio concatenation
sizeFormated = (sizeItem, sizeItem)
sizeDoubled = (sizeItem*2, sizeItem*2)
# open & resize & save to the appropriate directory
im = Image.open(iconPath)
im.thumbnail(sizeDoubled, Image.ANTIALIAS)
im.save(f'./{outputPathDoubled}/{iconName}')
im.thumbnail(sizeFormated, Image.ANTIALIAS)
im.save(f'./{outputPathFormated}/{iconName}')
if __name__ == '__main__':
main()