# we fork to execute vips job, in case of weird vips crash
pid = os.fork()
if pid: os.waitpid(pid, 0)
else:
from vipsCC import VImage, VMask
i = VImage.VImage(filename)
mx,my = 1728,1137
# double horizontal resolution
i = i.zoom(2,1)
# reduce the size of the image (only if needed)
x,y = i.Xsize(), i.Ysize()
xshrink = 1.0*x/mx
yshrink = 1.0*y/my
shrink = max(1.0, xshrink, yshrink)
print xshrink,yshrink,shrink
i = i.shrink(shrink,shrink)
# sharpen the image
i = i.conv(VMask.VIMask("sharpen.mask"))
# add white borders (if needed)
print i.Xsize(), i.Ysize()
i = i.embed(4, (mx-i.Xsize())/2, 0, mx, my)
# write final image
i.write("%s.png"%filename)
sys.exit(0)
assert not os.system("convert -monochrome -compress group4 %s.png %s.tiff"%
(filename,filename))
os.unlink("%s.png"%filename)
False and os.system("convert"
" -resize 200%%x100%% -sharpen 2 -sample '1728x1137>'"
" -bordercolor white -border 900 -gravity center "
" -crop 1728x1137+0+0 +repage "
" -monochrome -sharpen 2 -compress group4"
" %s %s.tiff"%(filename,filename))
assert not os.system("pdftoppm -r 200 -gray '%s' '%s'"%(filename,filename))
i=0 ; pages = []
while True:
i += 1
pagefilename = "%s-%d.pgm"%(filename,i)
if not os.path.isfile(pagefilename): break
image2fax(pagefilename)
os.unlink(pagefilename)
pages.append(pagefilename)
assert not os.system("tiffcp %s '%s'"%(
" ".join(["'%s.tiff'"%s for s in pages]), "%s.tiff"%filename))
for page in pages: os.unlink("%s.tiff"%page)
sys.exit(0)
if "image data" in filetype: