diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5cec076 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +__pycache__/ +*.pyc +*~ +app/uploads/ +app/mydatabase.db diff --git a/app/__init__.pyc b/app/__init__.pyc deleted file mode 100644 index b3828d2..0000000 Binary files a/app/__init__.pyc and /dev/null differ diff --git a/app/__pycache__/__init__.cpython-36.pyc b/app/__pycache__/__init__.cpython-36.pyc deleted file mode 100644 index 5bdcb03..0000000 Binary files a/app/__pycache__/__init__.cpython-36.pyc and /dev/null differ diff --git a/app/__pycache__/forms.cpython-36.pyc b/app/__pycache__/forms.cpython-36.pyc deleted file mode 100644 index 44774c3..0000000 Binary files a/app/__pycache__/forms.cpython-36.pyc and /dev/null differ diff --git a/app/__pycache__/models.cpython-36.pyc b/app/__pycache__/models.cpython-36.pyc deleted file mode 100644 index a37e942..0000000 Binary files a/app/__pycache__/models.cpython-36.pyc and /dev/null differ diff --git a/app/__pycache__/views.cpython-36.pyc b/app/__pycache__/views.cpython-36.pyc deleted file mode 100644 index 5215722..0000000 Binary files a/app/__pycache__/views.cpython-36.pyc and /dev/null differ diff --git a/app/cover.py b/app/cover.py new file mode 100644 index 0000000..1b0e04f --- /dev/null +++ b/app/cover.py @@ -0,0 +1,56 @@ +import PyPDF2 +from wand.image import Image +import io +import os + + +def pdf_page_to_png(src_pdf, pagenum = 0, resolution = 72,): + """ + Returns specified PDF page as wand.image.Image png. + :param PyPDF2.PdfFileReader src_pdf: PDF from which to take pages. + :param int pagenum: Page number to take. + :param int resolution: Resolution for resulting png in DPI. + """ + dst_pdf = PyPDF2.PdfFileWriter() + dst_pdf.addPage(src_pdf.getPage(pagenum)) + + pdf_bytes = io.BytesIO() + dst_pdf.write(pdf_bytes) + pdf_bytes.seek(0) + + img = Image(file = pdf_bytes, resolution = resolution) + img.convert("png") + + return img + + +def get_cover(file_path, filename): + # Main + # ==== + print(file_path) + src_filename = file_path + + src_pdf = PyPDF2.PdfFileReader(open(src_filename, "rb")) + + # What follows is a lookup table of page numbers within sample_log.pdf and the corresponding filenames. + pages = [{"pagenum": 0, "filename": filename}] + + # Convert each page to a png image. + for page in pages: + big_filename = "app/uploads/cover/"+page["filename"] + "_cover.png" + small_filename = "app/uploads/cover/"+page["filename"] + "cover_small" + ".png" + + img = pdf_page_to_png(src_pdf, pagenum = page["pagenum"], resolution = 300) + img.save(filename = big_filename) + + # Ensmallen + img.transform("", "200") + img.save(filename = small_filename) + + return page["filename"] + "_cover.png" + +#--- +#epub +#https://ebooks.stackexchange.com/questions/6517/command-line-extraction-of-metadata-title-author-from-epub-file +#https://hackage.haskell.org/package/epub-tools +#http://stackoverflow.com/questions/9751475/extract-cover-image-from-chm-and-epub-files diff --git a/app/forms.pyc b/app/forms.pyc deleted file mode 100644 index d265833..0000000 Binary files a/app/forms.pyc and /dev/null differ diff --git a/app/models.pyc b/app/models.pyc deleted file mode 100644 index de4931d..0000000 Binary files a/app/models.pyc and /dev/null differ diff --git a/app/templates/edit_book_detail.html b/app/templates/edit_book_detail.html new file mode 100644 index 0000000..5d5110c --- /dev/null +++ b/app/templates/edit_book_detail.html @@ -0,0 +1,37 @@ +{% extends 'base.html' %} + +{% block main %} +
red link page
+ +{% endblock %} diff --git a/app/views.pyc b/app/views.pyc deleted file mode 100644 index 9e0b4bf..0000000 Binary files a/app/views.pyc and /dev/null differ