裁剪封面宽高比可配置

This commit is contained in:
lededev
2022-04-10 13:38:48 +08:00
parent c54817aa01
commit 8add9fe424
4 changed files with 18 additions and 10 deletions

View File

@@ -7,9 +7,9 @@ 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):
aspect_ratio = config.getInstance().face_aspect_ratio()
# 新宽度是高度的2/3
cropWidthHalf = int(height/3)
try:
@@ -24,15 +24,15 @@ def face_crop_width(filename, width, height):
# 越界处理
if cropLeft < 0:
cropLeft = 0
cropRight = cropWidthHalf*g_width_half_ratio
cropRight = cropWidthHalf * aspect_ratio
elif cropRight > width:
cropLeft = width-cropWidthHalf*g_width_half_ratio
cropLeft = width - cropWidthHalf * aspect_ratio
cropRight = width
return (cropLeft, 0, cropRight, height)
except:
print('[-]Not found face! ' + filename)
# 默认靠右切
return (width-cropWidthHalf * g_width_half_ratio, 0, width, height)
return (width-cropWidthHalf * aspect_ratio, 0, width, height)
def face_crop_height(filename, width, height):
@@ -58,11 +58,13 @@ def face_crop_height(filename, width, height):
def cutImage(imagecut, path, fanart_path, poster_path, skip_facerec=False):
conf = config.getInstance()
fullpath_fanart = os.path.join(path, fanart_path)
fullpath_poster = os.path.join(path, poster_path)
if config.getInstance().face_aways_imagecut():
aspect_ratio = conf.face_aspect_ratio()
if conf.face_aways_imagecut():
imagecut = 1
elif config.getInstance().download_only_missing_images() and not file_not_exist_or_empty(fullpath_poster):
elif conf.download_only_missing_images() and not file_not_exist_or_empty(fullpath_poster):
return
if imagecut == 1: # 剪裁大封面
try:
@@ -71,7 +73,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) * g_width_half_ratio, 0, width, height))
img2 = img.crop((width - int(height/3) * aspect_ratio, 0, width, height))
else:
# 以人像为中心切取
img2 = img.crop(face_crop_width(fullpath_fanart, width, height))

View File

@@ -101,9 +101,10 @@ is performed. It may help you correct wrong numbers before real job.""")
no_net_op = False
if conf.main_mode() == 3:
no_net_op = args.no_network_operation
config.G_conf_override["common:stop_counter"] = 0
config.G_conf_override["common:rerun_delay"] = '0s'
config.G_conf_override["face:aways_imagecut"] = True
if no_net_op:
config.G_conf_override["common:stop_counter"] = 0
config.G_conf_override["common:rerun_delay"] = '0s'
config.G_conf_override["face:aways_imagecut"] = True
return args.file, args.number, args.logdir, args.regexstr, args.zero_op, no_net_op

View File

@@ -122,7 +122,9 @@ sites=38,39
; 人脸识别 locations_model=hog:方向梯度直方图(不太准确,速度快) cnn:深度学习模型(准确需要GPU/CUDA,速度慢)
; uncensored_only=0:对全部封面进行人脸识别 1:只识别无码封面,有码封面直接切右半部分
; aways_imagecut=0:按各网站默认行为 1:总是裁剪封面,开启此项将无视[common]download_only_missing_images=1总是覆盖封面
; 封面裁剪的宽高比可配置公式为aspect_ratio/3。默认aspect_ratio=2.12: 适配大部分有码影片封面前一版本默认为2/3即aspect_ratio=2
[face]
locations_model=hog
uncensored_only=1
aways_imagecut=0
aspect_ratio=2.12

View File

@@ -365,6 +365,9 @@ class Config:
def face_aways_imagecut(self) -> bool:
return self.getboolean_override("face", "aways_imagecut", fallback=False)
def face_aspect_ratio(self) -> float:
return self.conf.getfloat("face", "aspect_ratio", fallback=2.12)
@staticmethod
def _exit(sec: str) -> None:
print("[-] Read config error! Please check the {} section in config.ini", sec)