1
0
mirror of https://github.com/janeczku/calibre-web synced 2024-12-26 01:50:31 +00:00

Make PIL optional #885

This commit is contained in:
Ozzieisaacs 2019-04-17 20:45:08 +02:00
parent e1e79a73e8
commit 89516fc2d6
2 changed files with 57 additions and 47 deletions

View File

@ -62,7 +62,11 @@ except ImportError as e:
logger.warning('cannot import fb2, extracting fb2 metadata will not work: %s', e)
use_fb2_meta = False
try:
from PIL import Image
use_PIL = True
except ImportError:
use_PIL = False
def process(tmp_file_path, original_file_name, original_file_extension):
@ -133,6 +137,7 @@ def pdf_preview(tmp_file_path, tmp_dir):
if use_generic_pdf_cover:
return None
else:
if use_PIL:
try:
input1 = PdfFileReader(open(tmp_file_path, 'rb'), strict=False)
page0 = input1.getPage(0)
@ -173,7 +178,6 @@ def pdf_preview(tmp_file_path, tmp_dir):
# img.save(obj[1:] + ".png")
except Exception as ex:
print(ex)
try:
cover_file_name = os.path.splitext(tmp_file_path)[0] + ".cover.jpg"
with Image(filename=tmp_file_path + "[0]", resolution=150) as img:

View File

@ -35,7 +35,6 @@ from flask_babel import gettext as _
from flask_login import current_user
from babel.dates import format_datetime
from datetime import datetime
from PIL import Image
import shutil
import requests
try:
@ -52,6 +51,12 @@ try:
except ImportError:
use_unidecode = False
try:
from PIL import Image
use_PIL = True
except ImportError:
use_PIL = False
# Global variables
# updater_thread = None
global_WorkerThread = worker.WorkerThread()
@ -481,6 +486,7 @@ def save_cover(img, book_path):
web.app.logger.error("Only jpg/jpeg/png/webp files are supported as coverfile")
return False
if use_PIL:
# convert to jpg because calibre only supports jpg
if content_type in ('image/png', 'image/webp'):
if hasattr(img,'stream'):