预览图片等比缩小,jpg质量减小
This commit is contained in:
@@ -81,7 +81,16 @@ class BaseFrameProcessorWorker(threading.Thread):
|
|||||||
|
|
||||||
def _encode_image_to_base64(self, img) -> str:
|
def _encode_image_to_base64(self, img) -> str:
|
||||||
"""图像编码为 Base64"""
|
"""图像编码为 Base64"""
|
||||||
ok, buf = cv2.imencode(".jpg", img)
|
# 检查并调整图片尺寸
|
||||||
|
h, w = img.shape[:2]
|
||||||
|
if h > 720:
|
||||||
|
new_h = 720
|
||||||
|
new_w = int(w * (720 / h))
|
||||||
|
img = cv2.resize(img, (new_w, new_h), interpolation=cv2.INTER_AREA)
|
||||||
|
|
||||||
|
# 设置JPEG质量参数
|
||||||
|
params = [int(cv2.IMWRITE_JPEG_QUALITY), 80] # 质量0.8
|
||||||
|
ok, buf = cv2.imencode(".jpg", img, params)
|
||||||
if not ok:
|
if not ok:
|
||||||
raise RuntimeError("Failed to encode image to JPEG")
|
raise RuntimeError("Failed to encode image to JPEG")
|
||||||
return base64.b64encode(buf.tobytes()).decode("ascii")
|
return base64.b64encode(buf.tobytes()).decode("ascii")
|
||||||
|
|||||||
Reference in New Issue
Block a user