优化封面裁剪宽高比

This commit is contained in:
lededev
2022-04-10 10:09:40 +08:00
parent 09c81d7f59
commit 44dc26d13e

View File

@@ -7,6 +7,8 @@ from PIL import Image
import shutil
from ADC_function import file_not_exist_or_empty
g_width_half_ratio = 2.12
def face_crop_width(filename, width, height):
# 新宽度是高度的2/3
cropWidthHalf = int(height/3)
@@ -22,15 +24,15 @@ def face_crop_width(filename, width, height):
# 越界处理
if cropLeft < 0:
cropLeft = 0
cropRight = cropWidthHalf*2
cropRight = cropWidthHalf*g_width_half_ratio
elif cropRight > width:
cropLeft = width-cropWidthHalf*2
cropLeft = width-cropWidthHalf*g_width_half_ratio
cropRight = width
return (cropLeft, 0, cropRight, height)
except:
print('[-]Not found face! ' + filename)
# 默认靠右切
return (width-cropWidthHalf*2, 0, width, height)
return (width-cropWidthHalf * g_width_half_ratio, 0, width, height)
def face_crop_height(filename, width, height):
@@ -69,7 +71,7 @@ def cutImage(imagecut, path, fanart_path, poster_path, skip_facerec=False):
if width/height > 2/3: # 如果宽度大于2
if skip_facerec:
# 有码封面默认靠右切
img2 = img.crop((width - int(height/3) * 2, 0, width, height))
img2 = img.crop((width - int(height/3) * g_width_half_ratio, 0, width, height))
else:
# 以人像为中心切取
img2 = img.crop(face_crop_width(fullpath_fanart, width, height))