Skip to content

Commit

Permalink
添加uncensored标签到poster图片
Browse files Browse the repository at this point in the history
  • Loading branch information
cnzgray authored and Yuukiy committed Aug 17, 2024
1 parent 70f155d commit 1167dc9
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
9 changes: 6 additions & 3 deletions JavSP.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,8 @@ def reviewMovieID(all_movies, root):


SUBTITLE_MARK_FILE = os.path.abspath(mei_path('image/sub_mark.png'))
def crop_poster_wrapper(fanart_file, poster_file, method='normal', hard_sub=False):
UNCENSORED_MARK_FILE = os.path.abspath(mei_path('image/unc_mark.png'))
def crop_poster_wrapper(fanart_file, poster_file, method='normal', hard_sub=False, uncensored=False):
"""包装各种海报裁剪方法,提供统一的调用"""
if method == 'baidu':
try:
Expand All @@ -450,7 +451,9 @@ def crop_poster_wrapper(fanart_file, poster_file, method='normal', hard_sub=Fals
crop_poster(fanart_file, poster_file)
if cfg.Picture.add_label_to_cover:
if hard_sub == True:
add_label_to_poster(poster_file, SUBTITLE_MARK_FILE)
add_label_to_poster(poster_file, SUBTITLE_MARK_FILE, LabelPostion.BOTTOM_RIGHT)
if uncensored == True:
add_label_to_poster(poster_file, UNCENSORED_MARK_FILE, LabelPostion.BOTTOM_LEFT)


def RunNormalMode(all_movies):
Expand Down Expand Up @@ -517,7 +520,7 @@ def check_step(result, msg='步骤错误'):
else:
inner_bar.set_description('裁剪海报封面')
method = 'normal'
crop_poster_wrapper(movie.fanart_file, movie.poster_file, method, movie.hard_sub)
crop_poster_wrapper(movie.fanart_file, movie.poster_file, method, movie.hard_sub, movie.uncensored)
check_step(True)

if 'video_station' in cfg.NamingRule.media_servers:
Expand Down
22 changes: 19 additions & 3 deletions core/image.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""处理本地图片的相关功能"""
from enum import Enum
import os
import logging
from PIL import Image, ImageOps


__all__ = ['valid_pic', 'crop_poster', 'get_pic_size', 'add_label_to_poster']
__all__ = ['valid_pic', 'crop_poster', 'get_pic_size', 'add_label_to_poster', 'LabelPostion']

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -41,13 +42,28 @@ def crop_poster(fanart_file, poster_file):
# quality: from doc, default is 75, values above 95 should be avoided
poster.save(poster_file, quality=95)

# 位置枚举
class LabelPostion(Enum):
"""水印位置枚举"""
TOP_LEFT = 1
TOP_RIGHT = 2
BOTTOM_LEFT = 3
BOTTOM_RIGHT = 4

def add_label_to_poster(poster_file, mark_pic_file):
def add_label_to_poster(poster_file:str, mark_pic_file: str, pos: LabelPostion):
"""向poster中添加标签(水印)"""
poster = Image.open(poster_file)
mark_img = Image.open(mark_pic_file).convert('RGBA')
r,g,b,a = mark_img.split()
box = (poster.size[0] - mark_img.size[0], poster.size[1] - mark_img.size[1])
# 计算水印位置
if pos == LabelPostion.TOP_LEFT:
box = (0, 0)
elif pos == LabelPostion.TOP_RIGHT:
box = (poster.size[0] - mark_img.size[0], 0)
elif pos == LabelPostion.BOTTOM_LEFT:
box = (0, poster.size[1] - mark_img.size[1])
elif pos == LabelPostion.BOTTOM_RIGHT:
box = (poster.size[0] - mark_img.size[0], poster.size[1] - mark_img.size[1])
poster.paste(mark_img, box=box, mask=a)
poster.save(poster_file, quality=95)

Expand Down
Binary file modified image/sub_mark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image/unc_mark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1167dc9

Please sign in to comment.