From 3ba034ea0237185d72a847826f9fed8a79162f98 Mon Sep 17 00:00:00 2001 From: FrederikBaerentsen Date: Fri, 20 Jan 2023 15:17:50 +0100 Subject: [PATCH] Added thumbnail scaling and opds thumbnail preview --- config.py | 3 +++ main.py | 17 +++++++++++++---- opds/templates/catalog.opds.jinja2 | 3 +++ requirements.txt | 1 + 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/config.py b/config.py index d712352..14c5377 100644 --- a/config.py +++ b/config.py @@ -27,6 +27,9 @@ DEFAULT_SEARCH_NUMBER = 10 # True: logs are printet to terminal DEBUG = True +# Max thumbnail size +MAXSIZE = (500,500) + def _print(arg): if DEBUG: print(arg) diff --git a/main.py b/main.py index 2a54a23..d503e1e 100644 --- a/main.py +++ b/main.py @@ -5,6 +5,7 @@ from gevent.pywsgi import WSGIServer import timeit import sqlite3 import os +from PIL import Image import zipfile import gzip from bs4 import BeautifulSoup @@ -13,6 +14,7 @@ import datetime import sys import time from pathlib import Path +from io import BytesIO from opds import fromdir import config,extras @@ -65,9 +67,15 @@ def generate(): CVDB=extras.get_cvdb(Bs_data.select('Notes')) if force == 'True': cover = s.open(filelist[1]).read() - c = open(config.THUMBNAIL_DIR + "/" + str(CVDB) + ".jpg", 'wb+') - c.write(cover) - c.close() + + image = Image.open(BytesIO(cover)) + image.thumbnail(config.MAXSIZE,Image.ANTIALIAS) + image.save(config.THUMBNAIL_DIR + "/" + str(CVDB) + ".jpg") + + # Old way of saving without resize + #c = open(config.THUMBNAIL_DIR + "/" + str(CVDB) + ".jpg", 'wb+') + #c.write(cover) + #c.close() generated = generated + 1 elif Path(config.THUMBNAIL_DIR + "/" + str(CVDB) + ".jpg").exists() == False: cover = s.open(filelist[1]).read() @@ -81,7 +89,8 @@ def generate(): files_withtout_comicinfo = files_without_comicinfo + 1 except Exception as e: errorcount = errorcount + 1 - config._print("Error (/generate): " + e) + config._print("Error (/generate): " + str(e)) + config._print(f) return "Forced generation: " + str(force) + "
Comics: " + str(comiccount) + "
Generated: " + str(generated) + "
CBZ files without ComicInfo.xml: " + str(files_without_comicinfo) + "
Errors: " + str(errorcount) + "
Skipped: " + str(skippedcount) diff --git a/opds/templates/catalog.opds.jinja2 b/opds/templates/catalog.opds.jinja2 index 2754320..11b3d4a 100644 --- a/opds/templates/catalog.opds.jinja2 +++ b/opds/templates/catalog.opds.jinja2 @@ -37,6 +37,9 @@ + {% for link in entry.links %}