diff --git a/conf/app_d.ini b/conf/app_d.ini index 1952951..19c0923 100644 --- a/conf/app_d.ini +++ b/conf/app_d.ini @@ -14,4 +14,9 @@ path=./data/metadata.db [file] inputdir=./input storedir=./data/file -tmpdir=./data/tmp \ No newline at end of file +tmpdir=./data/tmp + +[img] +encode=jpg +miniSize=400 +fullSize=1000 \ No newline at end of file diff --git a/file.py b/file.py index ef3eff1..6df224e 100644 --- a/file.py +++ b/file.py @@ -79,7 +79,7 @@ def thumbnail(input, minSize: int = 600, encode:str="webp"): img = cv2.resize(img, newshape) if encode == "webp": success, encoded_image = cv2.imencode(".webp", img, [cv2.IMWRITE_WEBP_QUALITY, 75]) - elif encode == "jpg": + elif encode == "jpg" or "jpeg": success, encoded_image = cv2.imencode(".jpg", img, [cv2.IMWRITE_JPEG_QUALITY, 75]) else: return input diff --git a/web/api_Img.py b/web/api_Img.py index 6453c05..3911aec 100644 --- a/web/api_Img.py +++ b/web/api_Img.py @@ -1,9 +1,13 @@ from flask import * from flask import Blueprint -import db.file , file, gc +import db.file , file, gc , app_conf api_Img_bp = Blueprint("api_Img_bp", __name__) +conf = app_conf.conf() +imgencode = conf.get("img", "encode") +miniSize = conf.getint("img", "miniSize") +fullSize = conf.getint("img", "fullSize") @api_Img_bp.route("/api/img//") def img(bookid, index): # 图片接口 @@ -16,12 +20,12 @@ def img(bookid, index): # 图片接口 if isinstance(data, str): abort(404) if request.args.get("mini") == "yes": - data = file.thumbnail(data,encode="jpg") + data = file.thumbnail(data,miniSize,encode=imgencode) else: - data = file.thumbnail(data,1500) + data = file.thumbnail(data,fullSize,encode=imgencode) response = make_response(data) # 读取文件 del data - response.headers.set("Content-Type", "image/Webp") + response.headers.set("Content-Type",f"image/{imgencode}") response.headers.set("Content-Disposition", "inline", filename=filename) gc.collect() return response