-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert.py
52 lines (40 loc) · 1.49 KB
/
convert.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
50
from parsl import *
import os
from os.path import abspath
import argparse
dfk = DataFlowKernel(ThreadPoolExecutor(max_workers=8))
@App('python', dfk)
def process_image(photo, outputdir):
""" Process an image file.
"""
import os
import subprocess
max_xdim = 260
print("Photo : ", photo)
photo_info = subprocess.Popen(["identify", photo], stdout=subprocess.PIPE)
(myout, myerr) = photo_info.communicate()
if myerr:
print("error from the ImageMagick identify routine: %s" % (myerr.decode('ascii')))
myidentify = myout.decode('ascii').split(' ')
dims = myidentify[2]
xdim, ydim = dims.split('x')
xdim = int(xdim)
ydim = int(ydim)
while xdim > max_xdim:
xdim /= 2
ydim /= 2
mygeom = str(xdim)+'x'+str(ydim)
myoutputfile = outputdir + '/thumb.' + os.path.basename(photo)
myconvert = subprocess.run(["convert", "-geometry", mygeom, photo, myoutputfile])
return myconvert
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("-s", "--sourcedir", default='./pics', help="Folder containing the full size images")
parser.add_argument("-o", "--outdir", default='./pics', help="Folder to drop outputs into")
args = parser.parse_args()
if not os.path.exists(args.outdir):
os.makedirs(args.outdir)
for foto in os.listdir(args.sourcedir):
fotopath = abspath(args.sourcedir + '/' + foto)
process_image(fotopath, args.outdir)
print(fotopath)