check if wand is available, add dummy cover.jpg otherwise

pull/8/head
Cervinko Cera 9 years ago
parent e4ffc9f2a0
commit 51f1453917

@ -21,9 +21,14 @@ from functools import wraps
import base64 import base64
from sqlalchemy.sql import * from sqlalchemy.sql import *
import json import json
from wand.image import Image
import datetime import datetime
from uuid import uuid4 from uuid import uuid4
try:
from wand.image import Image
use_generic_pdf_cover = False
except ImportError, e:
use_generic_pdf_cover = True
from shutil import copyfile
app = (Flask(__name__)) app = (Flask(__name__))
@ -776,6 +781,11 @@ def upload():
file_size = os.path.getsize(saved_filename) file_size = os.path.getsize(saved_filename)
has_cover = 0 has_cover = 0
if fileextension.upper() == ".PDF": if fileextension.upper() == ".PDF":
if use_generic_pdf_cover:
basedir = os.path.dirname(__file__)
print basedir
copyfile(os.path.join(basedir, "static/generic_cover.jpg"), os.path.join(filepath, "cover.jpg"))
else:
with Image(filename=saved_filename + "[0]", resolution=150) as img: with Image(filename=saved_filename + "[0]", resolution=150) as img:
img.compression_quality = 88 img.compression_quality = 88
img.save(filename=os.path.join(filepath, "cover.jpg")) img.save(filename=os.path.join(filepath, "cover.jpg"))

Loading…
Cancel
Save