1 |
# (c) Tuomas J. Lukka |
# (c) Tuomas J. Lukka |
2 |
|
|
3 |
resolutions = [170, 50] |
import os |
4 |
|
import re |
5 |
|
|
6 |
pools = ["../../articlepool", "../../publicpool"] |
def convertFile(file, prefix, resolution): |
7 |
target = "../tmpimg" |
"""Convert a pageimagescroll to .png image files. |
8 |
|
|
9 |
do_all = 0 |
Parameters |
10 |
|
|
11 |
import os |
file: The filename to convert |
12 |
import re |
prefix: The prefix to use for the resulting files. |
13 |
|
If prefix is "ab" then the files of |
14 |
|
a three-page .pdf will be |
15 |
|
"ab1", "ab2" and "ab3". Note: 1-based. |
16 |
|
""" |
17 |
|
print "Processing ",file |
18 |
|
l = os.popen("file -i -b %(pool)s/%(file)s" % locals()).readlines()[0] |
19 |
|
l = l.rstrip().lstrip() |
20 |
|
print "'%(l)s'" % locals() |
21 |
|
|
22 |
|
if l != "application/pdf" and l != "application/postscript": |
23 |
|
print "Unknown - ignoring" |
24 |
|
return 0 |
25 |
|
|
26 |
|
cmdline = "gs -dBATCH -dNOPAUSE -sDEVICE=png256 -r%(res)s -sOutputFile=%(prefix)%%d %(file)s" % locals() |
27 |
|
print "RUNNING ",cmdline |
28 |
|
res = os.system(cmdline) |
29 |
|
if res: |
30 |
|
print "Error running gs",res |
31 |
|
return 0 |
32 |
|
|
33 |
|
return 1 |
34 |
|
|
|
def convertFile(block, toPrefix): |
|
35 |
|
|
|
def doPool(pool): |
|
|
for file in os.listdir(pool): |
|
|
if not file.startswith("data_"): continue |
|
|
print "Processing ",file |
|
|
l = os.popen("file -i -b %(pool)s/%(file)s" % locals()).readlines()[0] |
|
|
l = l.rstrip().lstrip() |
|
|
print "'%(l)s'" % locals() |
|
|
|
|
|
if l != "application/pdf" and l != "application/postscript": |
|
|
print "Unknown - ignoring" |
|
|
continue |
|
|
block = "urn:x-storm:1.0:"+l+"," + file[5:] |
|
|
block = block.replace("/", "__") |
|
|
print "into ",block |
|
|
|
|
|
for res in resolutions: |
|
|
targetdir = target |
|
|
cmdline = "gs -dBATCH -dNOPAUSE -sDEVICE=png256 -r%(res)s -sOutputFile=%(targetdir)s/%(block)s-%(res)s-%%d %(pool)s/%(file)s" % locals() |
|
|
print "RUNNING ",cmdline |
|
|
os.system(cmdline) |
|
|
|
|
|
if __name__ == '__main__': |
|
|
for pool in pools: doPool(pool) |
|
|
|
|