fread/helpers/__init__.py

36 lines
769 B
Python
Raw Normal View History

2017-02-08 22:55:14 +00:00
import errno, os, PIL, fpdf
2017-02-08 23:39:07 +00:00
JPG = 0
PNG = 1
def makeDir(issue):
try:
os.makedirs(str(issue))
return True
except OSError as e:
if e.errno != errno.EEXIST:
raise
return False
2017-02-08 23:39:07 +00:00
def makePDF(issue, pages, type = JPG):
ext = "jpg" if type == JPG else "png"
cover = PIL.Image.open("%s/1.%s" % (str(issue), ext))
x, y = cover.size
pdf = fpdf.FPDF(unit = "pt", format = [x, y])
for page in range(pages):
pdf.add_page()
2017-02-08 23:39:07 +00:00
pdf.image("%s/%i.%s" % (str(issue), page + 1, ext), 0, 0)
pdf.output("%s/issue.pdf" % str(issue), "F")
2017-07-16 10:40:19 +00:00
def downloadPage(canvas, issue, page, driver):
b64 = driver.execute_script("return arguments[0].toDataURL('image/png').substring(21);", canvas)
with open("%s/%i.png" % (str(issue), int(page)), "b+w") as o:
2017-07-16 10:40:19 +00:00
o.write(b64)