-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptimise.py
More file actions
30 lines (25 loc) · 777 Bytes
/
Copy pathoptimise.py
File metadata and controls
30 lines (25 loc) · 777 Bytes
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
import os
import sys
from imageoptim import ImageOptimAPI
dir = os.path.abspath(os.path.dirname(__file__))
def main():
api = ImageOptimAPI('zwwpvcxnbr');
src_dir = os.path.join(dir, 'src');
for fn in os.listdir(src_dir):
file_path = {
'src': os.path.join(src_dir, fn),
'output': os.path.join(dir, 'output', fn)
}
# If file does not exist, resize it
if(os.path.isfile(file_path['output'])):
print('File %s already exists - skipping' % fn)
else:
print('Optimising %s' % fn)
options={
'crop': True,
# 'quality': 'high'
}
img = api.image_from_file_path(file_path['src'], options=options, resize_pow2=True)
img.save(os.path.join(dir, 'output', fn))
if __name__ == "__main__":
main()