优化封面裁剪宽高比
This commit is contained in:
@@ -7,6 +7,8 @@ from PIL import Image
|
|||||||
import shutil
|
import shutil
|
||||||
from ADC_function import file_not_exist_or_empty
|
from ADC_function import file_not_exist_or_empty
|
||||||
|
|
||||||
|
g_width_half_ratio = 2.12
|
||||||
|
|
||||||
def face_crop_width(filename, width, height):
|
def face_crop_width(filename, width, height):
|
||||||
# 新宽度是高度的2/3
|
# 新宽度是高度的2/3
|
||||||
cropWidthHalf = int(height/3)
|
cropWidthHalf = int(height/3)
|
||||||
@@ -22,15 +24,15 @@ def face_crop_width(filename, width, height):
|
|||||||
# 越界处理
|
# 越界处理
|
||||||
if cropLeft < 0:
|
if cropLeft < 0:
|
||||||
cropLeft = 0
|
cropLeft = 0
|
||||||
cropRight = cropWidthHalf*2
|
cropRight = cropWidthHalf*g_width_half_ratio
|
||||||
elif cropRight > width:
|
elif cropRight > width:
|
||||||
cropLeft = width-cropWidthHalf*2
|
cropLeft = width-cropWidthHalf*g_width_half_ratio
|
||||||
cropRight = width
|
cropRight = width
|
||||||
return (cropLeft, 0, cropRight, height)
|
return (cropLeft, 0, cropRight, height)
|
||||||
except:
|
except:
|
||||||
print('[-]Not found face! ' + filename)
|
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):
|
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 width/height > 2/3: # 如果宽度大于2
|
||||||
if skip_facerec:
|
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:
|
else:
|
||||||
# 以人像为中心切取
|
# 以人像为中心切取
|
||||||
img2 = img.crop(face_crop_width(fullpath_fanart, width, height))
|
img2 = img.crop(face_crop_width(fullpath_fanart, width, height))
|
||||||
|
|||||||
Reference in New Issue
Block a user