-
Notifications
You must be signed in to change notification settings - Fork 0
/
pack.coffee
91 lines (60 loc) · 2.14 KB
/
pack.coffee
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
shelljs = require 'shelljs/global'
arg = require 'commander'
arg
.option('-s, --source <source>', 'Source', '')
.option('-o, --output <output>', 'Output', '')
.option('-f, --framesperpack <framesperpack>', 'Frames per pack', '')
.option('-r, --resize <resize>', '100', '')
.option('-t, --type <type>', '', '')
.option('-w, --width <width>', 'Original width', '')
.option('-h, --height <height>', 'Original height', '')
.option('-e, --extension <extension>', 'File extension', 'jpg')
.option('-d, --duration <duration>', 'Video duration', 1)
.parse(process.argv)
pack_images = ( dir, width, height ) ->
console.log arg.duration
cmd = "python packImages.py --src #{dir} --out #{arg.output} --width #{width} --height #{height} --duration #{arg.duration} --imagesperpack #{arg.framesperpack}"
exec cmd, (code, output) ->
echo 'Exit code:', code
echo 'Program output:', output
# Remove the tmp directory
# rm '-rf', dir
# pack_images '_1439203061015_sd'
# return
process_images = ->
# if not test '-d', arg.output
# mkdir arg.output
# Create a tmp directory
tmp_dir = '_' + String(Date.now()) + '_' + arg.type
mkdir '-p', tmp_dir
# Copy all source images to tmp directory
cp '-R', "#{arg.source}/*", tmp_dir
# Generate a list of commands to resize the images
cmds = []
remFiles = []
WIDTH = parseInt(arg.width) * parseFloat(arg.resize / 100)
HEIGHT = parseInt(arg.height) * parseFloat(arg.resize / 100)
for file, i in ls "#{tmp_dir}/*.jpg"
switch arg.extension
when 'webp'
outfile = file.replace('.jpg', '.webp')
cmds.push "cwebp -resize #{WIDTH} #{HEIGHT} #{file} -o #{outfile} -quiet"
remFiles.push(file)
else
cmds.push "convert -strip -interlace Plane -gaussian-blur 0.05 -quality 85% #{file} -resize #{arg.resize}% #{file}"
num_cmds = cmds.length
progress = 0
run = (cmds) =>
if cmds.length is 0
rm( remFiles )
pack_images tmp_dir, WIDTH, HEIGHT
return
echo "Progress #{progress} / #{num_cmds}"
cmd = cmds.shift()
exec cmd, (code, output) ->
# console.log('Exit code:', code);
# console.log('Program output:', output);
progress++
run cmds
run cmds
do process_images