-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathspecproc.py
More file actions
93 lines (75 loc) · 3.14 KB
/
specproc.py
File metadata and controls
93 lines (75 loc) · 3.14 KB
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
92
93
import sqlite3
import os
if __name__ == '__main__':
# with open('/tmp/out.txt', 'rb') as fd:
# s = fd.read()
# ll = s.split('\n')
# otl = []
# s = '''UPDATE all_comics SET width=?, height=?, ratio=? WHERE comicid=?;'''
#
# with sqlite3.connect('data/gazee_comics.db') as con:
#
# for l in ll:
# if l.strip() == '':
# continue
# tl = l.strip().split(',')
# id = int(tl[0].split('-')[0], 10)
# w = int(tl[1], 10)
# h = int(tl[2], 10)
# ratio = (1.0) * w / h
# otl.append( (w,h,ratio,id) )
#
# print "Committing %d records..." % len(otl)
# con.executemany(s, otl)
# con.commit()
tgtw = 225
tgth = 300
with sqlite3.connect('data/gazee_comics.db') as con:
sql = '''SELECT comicid, width, height, ratio FROM all_comics;'''
for row in con.execute(sql):
cid, w, h, ratio = row
if w == 0 or h == 0:
continue
part = (cid // 512)
if ratio >= 1.2:
rot = 90
tw = h
h = w
w = tw
ratio = (1.0) * w / h
print("convert data/cache/%d/%d-native.jpg -rotate 90 -thumbnail %dx%d data/cache/%d/%d-%dx%d.jpg" % (part, cid, tgtw, tgth, part, cid, tgtw, tgth))
# continue
else:
rot = 0
# print("%d [ %d x %d ] (%.4f)" % (cid, w, h, ratio))
h1 = tgth
w1 = int(h1 * ratio)
w2 = tgtw
h2 = int(w2 / ratio)
# print("Opt1: %d x %d Opt2: %d x %d" % (w1, h1, w2, h2))
if (w1 > tgtw):
infn = "data/cache/%d/%d-%dx%d.jpg" % (part, cid, tgtw, tgth)
ofn = "data/cache/%d/p%d-%dx%d.jpg" % (part, cid, tgtw, tgth)
# print("convert data/cache/%d/p%d-%dx%d.jpg -rotate 90 -thumbnail %dx%d %s" % (part, cid, tgtw, tgth, tgtw, tgth, infn))
pw = w2
ph = h2
fixh = tgth - ph
origfixh = fixh
if ((fixh %2) == 1):
fixh += 1
fixwh = fixh // 2
# print("w1, h1 (%d, %d) w2, h2 (%d, %d)" % (w1, h1, w2, h2))
if rot == 90 or not os.path.exists(ofn):
print("bash imageborder -s 0x%d -p 20 -e edge -b 2 %s %s" % (fixwh, infn, ofn))
else:
pw = w1
ph = h1
fixw = tgtw - pw
origfixw = fixw
if ((fixw % 2) == 1):
fixw += 1
fixwb = fixw//2
ofn = "data/cache/%d/p%d-%dx%d.jpg" % (part, cid, tgtw, tgth)
if rot == 90 or not os.path.exists(ofn):
print("bash imageborder -s %dx0 -p 20 -e edge -b 2 data/cache/%d/%d-300x400.jpg %s" % (fixwb, part, cid, ofn))
print("echo %d..." % cid)