Merge branch 'bugfix_overlay' into develop
This commit is contained in:
@@ -340,11 +340,25 @@ class Controller:
|
|||||||
model.logger.info(f"[SENT] {message}{translation}")
|
model.logger.info(f"[SENT] {message}{translation}")
|
||||||
|
|
||||||
if config.OVERLAY_LARGE_LOG is True and model.overlay.initialized is True:
|
if config.OVERLAY_LARGE_LOG is True and model.overlay.initialized is True:
|
||||||
if config.OVERLAY_SHOW_ONLY_TRANSLATED_MESSAGES is True and len(translation) > 0:
|
if config.OVERLAY_SHOW_ONLY_TRANSLATED_MESSAGES is True:
|
||||||
overlay_image = model.createOverlayImageLargeLog("send", translation[0], "")
|
if len(translation) > 0:
|
||||||
|
overlay_image = model.createOverlayImageLargeLog(
|
||||||
|
"send",
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
translation,
|
||||||
|
config.SELECTED_TARGET_LANGUAGES[config.SELECTED_TAB_NO]
|
||||||
|
)
|
||||||
|
model.updateOverlayLargeLog(overlay_image)
|
||||||
else:
|
else:
|
||||||
overlay_image = model.createOverlayImageLargeLog("send", message, translation[0] if len(translation) > 0 else "")
|
overlay_image = model.createOverlayImageLargeLog(
|
||||||
model.updateOverlayLargeLog(overlay_image)
|
"send",
|
||||||
|
message,
|
||||||
|
config.SELECTED_YOUR_LANGUAGES[config.SELECTED_TAB_NO]["1"]["language"],
|
||||||
|
translation,
|
||||||
|
config.SELECTED_TARGET_LANGUAGES[config.SELECTED_TAB_NO]
|
||||||
|
)
|
||||||
|
model.updateOverlayLargeLog(overlay_image)
|
||||||
|
|
||||||
def speakerMessage(self, result:dict) -> None:
|
def speakerMessage(self, result:dict) -> None:
|
||||||
message = result["text"]
|
message = result["text"]
|
||||||
@@ -418,18 +432,43 @@ class Controller:
|
|||||||
|
|
||||||
if config.ENABLE_TRANSCRIPTION_RECEIVE is True:
|
if config.ENABLE_TRANSCRIPTION_RECEIVE is True:
|
||||||
if config.OVERLAY_SMALL_LOG is True and model.overlay.initialized is True:
|
if config.OVERLAY_SMALL_LOG is True and model.overlay.initialized is True:
|
||||||
if config.OVERLAY_SHOW_ONLY_TRANSLATED_MESSAGES is True and len(translation) > 0:
|
if config.OVERLAY_SHOW_ONLY_TRANSLATED_MESSAGES is True:
|
||||||
overlay_image = model.createOverlayImageSmallLog(translation[0], "")
|
if len(translation) > 0:
|
||||||
|
overlay_image = model.createOverlayImageSmallLog(
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
translation,
|
||||||
|
config.SELECTED_YOUR_LANGUAGES[config.SELECTED_TAB_NO],
|
||||||
|
)
|
||||||
|
model.updateOverlaySmallLog(overlay_image)
|
||||||
else:
|
else:
|
||||||
overlay_image = model.createOverlayImageSmallLog(message, translation[0] if len(translation) > 0 else "")
|
overlay_image = model.createOverlayImageSmallLog(
|
||||||
model.updateOverlaySmallLog(overlay_image)
|
message,
|
||||||
|
language,
|
||||||
|
translation,
|
||||||
|
config.SELECTED_YOUR_LANGUAGES[config.SELECTED_TAB_NO],
|
||||||
|
)
|
||||||
|
model.updateOverlaySmallLog(overlay_image)
|
||||||
|
|
||||||
if config.OVERLAY_LARGE_LOG is True and model.overlay.initialized is True:
|
if config.OVERLAY_LARGE_LOG is True and model.overlay.initialized is True:
|
||||||
if config.OVERLAY_SHOW_ONLY_TRANSLATED_MESSAGES is True and len(translation) > 0:
|
if config.OVERLAY_SHOW_ONLY_TRANSLATED_MESSAGES is True:
|
||||||
overlay_image = model.createOverlayImageLargeLog("receive", translation[0], "")
|
if len(translation) > 0:
|
||||||
|
overlay_image = model.createOverlayImageLargeLog(
|
||||||
|
"receive",
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
translation,
|
||||||
|
)
|
||||||
|
model.updateOverlayLargeLog(overlay_image)
|
||||||
else:
|
else:
|
||||||
overlay_image = model.createOverlayImageLargeLog("receive", message, translation[0] if len(translation) > 0 else "")
|
overlay_image = model.createOverlayImageLargeLog(
|
||||||
model.updateOverlayLargeLog(overlay_image)
|
"receive",
|
||||||
|
message,
|
||||||
|
language,
|
||||||
|
translation,
|
||||||
|
config.SELECTED_YOUR_LANGUAGES[config.SELECTED_TAB_NO]
|
||||||
|
)
|
||||||
|
model.updateOverlayLargeLog(overlay_image)
|
||||||
|
|
||||||
if config.SEND_RECEIVED_MESSAGE_TO_VRC is True:
|
if config.SEND_RECEIVED_MESSAGE_TO_VRC is True:
|
||||||
osc_message = self.messageFormatter("RECEIVED", translation, [message])
|
osc_message = self.messageFormatter("RECEIVED", translation, [message])
|
||||||
@@ -544,11 +583,25 @@ class Controller:
|
|||||||
model.oscSendMessage(osc_message)
|
model.oscSendMessage(osc_message)
|
||||||
|
|
||||||
if config.OVERLAY_LARGE_LOG is True:
|
if config.OVERLAY_LARGE_LOG is True:
|
||||||
if config.OVERLAY_SHOW_ONLY_TRANSLATED_MESSAGES is True and len(translation) > 0:
|
if config.OVERLAY_SHOW_ONLY_TRANSLATED_MESSAGES is True:
|
||||||
overlay_image = model.createOverlayImageLargeLog("send", translation[0], "")
|
if len(translation) > 0:
|
||||||
|
overlay_image = model.createOverlayImageLargeLog(
|
||||||
|
"send",
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
translation,
|
||||||
|
config.SELECTED_TARGET_LANGUAGES[config.SELECTED_TAB_NO],
|
||||||
|
)
|
||||||
|
model.updateOverlayLargeLog(overlay_image)
|
||||||
else:
|
else:
|
||||||
overlay_image = model.createOverlayImageLargeLog("send", message, translation[0] if len(translation) > 0 else "")
|
overlay_image = model.createOverlayImageLargeLog(
|
||||||
model.updateOverlayLargeLog(overlay_image)
|
"send",
|
||||||
|
message,
|
||||||
|
config.SELECTED_YOUR_LANGUAGES[config.SELECTED_TAB_NO]["1"]["language"],
|
||||||
|
translation,
|
||||||
|
config.SELECTED_TARGET_LANGUAGES[config.SELECTED_TAB_NO],
|
||||||
|
)
|
||||||
|
model.updateOverlayLargeLog(overlay_image)
|
||||||
|
|
||||||
if model.checkWebSocketServerAlive() is True:
|
if model.checkWebSocketServerAlive() is True:
|
||||||
model.websocketSendMessage(
|
model.websocketSendMessage(
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ class Model:
|
|||||||
"large": overlay_large_log_settings,
|
"large": overlay_large_log_settings,
|
||||||
}
|
}
|
||||||
self.overlay = Overlay(overlay_settings)
|
self.overlay = Overlay(overlay_settings)
|
||||||
self.overlay_image = OverlayImage()
|
self.overlay_image = OverlayImage(config.PATH_LOCAL)
|
||||||
self.mic_audio_queue = None
|
self.mic_audio_queue = None
|
||||||
self.mic_mute_status = None
|
self.mic_mute_status = None
|
||||||
self.kks = kakasi()
|
self.kks = kakasi()
|
||||||
@@ -717,21 +717,20 @@ class Model:
|
|||||||
self.speaker_energy_recorder.stop()
|
self.speaker_energy_recorder.stop()
|
||||||
self.speaker_energy_recorder = None
|
self.speaker_energy_recorder = None
|
||||||
|
|
||||||
def createOverlayImageSmallLog(self, message, translation):
|
def createOverlayImageSmallLog(self, message:str, your_language:str, translation:list, target_language:dict):
|
||||||
your_language = config.SELECTED_TARGET_LANGUAGES[config.SELECTED_TAB_NO]["1"]["language"]
|
target_language = [data["language"] for data in target_language.values() if data["enable"] is True]
|
||||||
target_language = config.SELECTED_YOUR_LANGUAGES[config.SELECTED_TAB_NO]["1"]["language"]
|
|
||||||
return self.overlay_image.createOverlayImageSmallLog(message, your_language, translation, target_language)
|
return self.overlay_image.createOverlayImageSmallLog(message, your_language, translation, target_language)
|
||||||
|
|
||||||
def createOverlayImageSmallMessage(self, message):
|
def createOverlayImageSmallMessage(self, message):
|
||||||
ui_language = config.UI_LANGUAGE
|
ui_language = config.UI_LANGUAGE
|
||||||
convert_languages = {
|
convert_languages = {
|
||||||
"en": "Japanese",
|
"en": "Default",
|
||||||
"jp": "Japanese",
|
"jp": "Japanese",
|
||||||
"ko":"Korean",
|
"ko":"Korean",
|
||||||
"zh-Hans":"Chinese Simplified",
|
"zh-Hans":"Chinese Simplified",
|
||||||
"zh-Hant":"Chinese Traditional",
|
"zh-Hant":"Chinese Traditional",
|
||||||
}
|
}
|
||||||
language = convert_languages.get(ui_language, "Japanese")
|
language = convert_languages.get(ui_language, "Default")
|
||||||
return self.overlay_image.createOverlayImageSmallLog(message, language)
|
return self.overlay_image.createOverlayImageSmallLog(message, language)
|
||||||
|
|
||||||
def clearOverlayImageSmallLog(self):
|
def clearOverlayImageSmallLog(self):
|
||||||
@@ -769,22 +768,21 @@ class Model:
|
|||||||
if (self.overlay.settings[size]["ui_scaling"] != config.OVERLAY_SMALL_LOG_SETTINGS["ui_scaling"]):
|
if (self.overlay.settings[size]["ui_scaling"] != config.OVERLAY_SMALL_LOG_SETTINGS["ui_scaling"]):
|
||||||
self.overlay.updateUiScaling(config.OVERLAY_SMALL_LOG_SETTINGS["ui_scaling"], size)
|
self.overlay.updateUiScaling(config.OVERLAY_SMALL_LOG_SETTINGS["ui_scaling"], size)
|
||||||
|
|
||||||
def createOverlayImageLargeLog(self, message_type:str, message:str, translation:str):
|
def createOverlayImageLargeLog(self, message_type:str, message:str, your_language:str, translation:list, target_language:dict):
|
||||||
your_language = config.SELECTED_TARGET_LANGUAGES[config.SELECTED_TAB_NO]["1"]["language"]
|
target_language = [data["language"] for data in target_language.values() if data["enable"] is True]
|
||||||
target_language = config.SELECTED_YOUR_LANGUAGES[config.SELECTED_TAB_NO]["1"]["language"]
|
|
||||||
return self.overlay_image.createOverlayImageLargeLog(message_type, message, your_language, translation, target_language)
|
return self.overlay_image.createOverlayImageLargeLog(message_type, message, your_language, translation, target_language)
|
||||||
|
|
||||||
def createOverlayImageLargeMessage(self, message):
|
def createOverlayImageLargeMessage(self, message):
|
||||||
ui_language = config.UI_LANGUAGE
|
ui_language = config.UI_LANGUAGE
|
||||||
convert_languages = {
|
convert_languages = {
|
||||||
"en": "Japanese",
|
"en": "Default",
|
||||||
"jp": "Japanese",
|
"jp": "Japanese",
|
||||||
"ko":"Korean",
|
"ko":"Korean",
|
||||||
"zh-Hans":"Chinese Simplified",
|
"zh-Hans":"Chinese Simplified",
|
||||||
"zh-Hant":"Chinese Traditional",
|
"zh-Hant":"Chinese Traditional",
|
||||||
}
|
}
|
||||||
language = convert_languages.get(ui_language, "Japanese")
|
language = convert_languages.get(ui_language, "Default")
|
||||||
overlay_image = OverlayImage()
|
overlay_image = OverlayImage(config.PATH_LOCAL)
|
||||||
|
|
||||||
for _ in range(2):
|
for _ in range(2):
|
||||||
overlay_image.createOverlayImageLargeLog("send", message, language)
|
overlay_image.createOverlayImageLargeLog("send", message, language)
|
||||||
|
|||||||
@@ -11,14 +11,20 @@ except ImportError:
|
|||||||
|
|
||||||
class OverlayImage:
|
class OverlayImage:
|
||||||
LANGUAGES = {
|
LANGUAGES = {
|
||||||
"Japanese": "NotoSansJP-Regular",
|
"Default": "NotoSansJP-Regular.ttf",
|
||||||
"Korean": "NotoSansKR-Regular",
|
"Japanese": "NotoSansJP-Regular.ttf",
|
||||||
"Chinese Simplified": "NotoSansSC-Regular",
|
"Korean": "NotoSansKR-Regular.ttf",
|
||||||
"Chinese Traditional": "NotoSansTC-Regular",
|
"Chinese Simplified": "NotoSansSC-Regular.ttf",
|
||||||
|
"Chinese Traditional": "NotoSansTC-Regular.ttf",
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, root_path: str=None):
|
||||||
self.message_log = []
|
self.message_log = []
|
||||||
|
if root_path is None:
|
||||||
|
self.root_path = os_path.join(os_path.dirname(__file__), "..", "..", "..", "fonts")
|
||||||
|
else:
|
||||||
|
self.root_path = os_path.join(root_path, "_internal", "fonts")
|
||||||
|
print(self.root_path)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def concatenateImagesVertically(img1: Image, img2: Image, margin: int = 0) -> Image:
|
def concatenateImagesVertically(img1: Image, img2: Image, margin: int = 0) -> Image:
|
||||||
@@ -54,16 +60,16 @@ class OverlayImage:
|
|||||||
return colors
|
return colors
|
||||||
|
|
||||||
def createTextboxSmallLog(self, text:str, language:str, text_color:tuple, base_width:int, base_height:int, font_size:int) -> Image:
|
def createTextboxSmallLog(self, text:str, language:str, text_color:tuple, base_width:int, base_height:int, font_size:int) -> Image:
|
||||||
font_family = self.LANGUAGES.get(language, "NotoSansJP-Regular")
|
font_family = self.LANGUAGES.get(language, self.LANGUAGES["Default"])
|
||||||
img = Image.new("RGBA", (base_width, base_height), (0, 0, 0, 0))
|
img = Image.new("RGBA", (base_width, base_height), (0, 0, 0, 0))
|
||||||
draw = ImageDraw.Draw(img)
|
draw = ImageDraw.Draw(img)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
font_path = os_path.join(os_path.dirname(os_path.dirname(os_path.dirname(__file__))), "fonts", f"{font_family}.ttf")
|
font_path = os_path.join(self.root_path, font_family)
|
||||||
font = ImageFont.truetype(font_path, font_size)
|
font = ImageFont.truetype(font_path, font_size)
|
||||||
except Exception:
|
except Exception:
|
||||||
errorLogging()
|
errorLogging()
|
||||||
font_path = os_path.join(os_path.dirname(__file__), "..", "..", "..", "fonts", f"{font_family}.ttf")
|
font_path = os_path.join(os_path.dirname(__file__), "..", "..", "..", "fonts", font_family)
|
||||||
font = ImageFont.truetype(font_path, font_size)
|
font = ImageFont.truetype(font_path, font_size)
|
||||||
|
|
||||||
text_width = draw.textlength(text, font)
|
text_width = draw.textlength(text, font)
|
||||||
@@ -80,7 +86,8 @@ class OverlayImage:
|
|||||||
draw.text((text_x, text_y), text, text_color, anchor="mm", stroke_width=0, font=font, align="center")
|
draw.text((text_x, text_y), text, text_color, anchor="mm", stroke_width=0, font=font, align="center")
|
||||||
return img
|
return img
|
||||||
|
|
||||||
def createOverlayImageSmallLog(self, message:str, your_language:str, translation:str="", target_language:str=None) -> Image:
|
def createOverlayImageSmallLog(self, message: str, your_language: str, translation: list = [], target_language: list = []) -> Image:
|
||||||
|
# UI設定を取得
|
||||||
ui_size = self.getUiSizeSmallLog()
|
ui_size = self.getUiSizeSmallLog()
|
||||||
width, height, font_size = ui_size["width"], ui_size["height"], ui_size["font_size"]
|
width, height, font_size = ui_size["width"], ui_size["height"], ui_size["font_size"]
|
||||||
|
|
||||||
@@ -89,16 +96,41 @@ class OverlayImage:
|
|||||||
background_color = ui_colors["background_color"]
|
background_color = ui_colors["background_color"]
|
||||||
background_outline_color = ui_colors["background_outline_color"]
|
background_outline_color = ui_colors["background_outline_color"]
|
||||||
|
|
||||||
img = self.createTextboxSmallLog(message, your_language, text_color, width, height, font_size)
|
# テキストボックス画像のリストを作成
|
||||||
if translation and target_language:
|
textbox_images = []
|
||||||
translation_img = self.createTextboxSmallLog(translation, target_language, text_color, width, height, font_size)
|
|
||||||
img = self.concatenateImagesVertically(img, translation_img)
|
|
||||||
|
|
||||||
|
# 翻訳がある場合
|
||||||
|
if translation and target_language:
|
||||||
|
# 元のメッセージがある場合は追加
|
||||||
|
if message:
|
||||||
|
textbox_images.append(
|
||||||
|
self.createTextboxSmallLog(message, your_language, text_color, width, height, font_size)
|
||||||
|
)
|
||||||
|
|
||||||
|
# 翻訳をすべて追加
|
||||||
|
for trans, lang in zip(translation, target_language):
|
||||||
|
textbox_images.append(
|
||||||
|
self.createTextboxSmallLog(trans, lang, text_color, width, height, font_size)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
# 翻訳がない場合は元のメッセージのみ
|
||||||
|
textbox_images.append(
|
||||||
|
self.createTextboxSmallLog(message, your_language, text_color, width, height, font_size)
|
||||||
|
)
|
||||||
|
|
||||||
|
# すべてのテキストボックスを縦に結合
|
||||||
|
img = textbox_images[0]
|
||||||
|
for textbox_img in textbox_images[1:]:
|
||||||
|
img = self.concatenateImagesVertically(img, textbox_img)
|
||||||
|
|
||||||
|
# 角丸背景を作成
|
||||||
background = Image.new("RGBA", img.size, (0, 0, 0, 0))
|
background = Image.new("RGBA", img.size, (0, 0, 0, 0))
|
||||||
draw = ImageDraw.Draw(background)
|
draw = ImageDraw.Draw(background)
|
||||||
draw.rounded_rectangle([(0, 0), img.size], radius=50, fill=background_color, outline=background_outline_color, width=5)
|
draw.rounded_rectangle([(0, 0), img.size], radius=50, fill=background_color, outline=background_outline_color, width=5)
|
||||||
|
|
||||||
return Image.alpha_composite(background, img)
|
# 背景とテキストを合成
|
||||||
|
img = Image.alpha_composite(background, img)
|
||||||
|
return img
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def getUiSizeLargeLog() -> dict:
|
def getUiSizeLargeLog() -> dict:
|
||||||
@@ -131,17 +163,17 @@ class OverlayImage:
|
|||||||
anchor = "lm" if message_type == "receive" else "rm"
|
anchor = "lm" if message_type == "receive" else "rm"
|
||||||
text_x = 0 if message_type == "receive" else ui_size["width"]
|
text_x = 0 if message_type == "receive" else ui_size["width"]
|
||||||
align = "left" if message_type == "receive" else "right"
|
align = "left" if message_type == "receive" else "right"
|
||||||
font_family = self.LANGUAGES.get(language, "NotoSansJP-Regular")
|
font_family = self.LANGUAGES.get(language, self.LANGUAGES["Default"])
|
||||||
|
|
||||||
img = Image.new("RGBA", (0, 0), (0, 0, 0, 0))
|
img = Image.new("RGBA", (0, 0), (0, 0, 0, 0))
|
||||||
draw = ImageDraw.Draw(img)
|
draw = ImageDraw.Draw(img)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
font_path = os_path.join(os_path.dirname(os_path.dirname(os_path.dirname(__file__))), "fonts", f"{font_family}.ttf")
|
font_path = os_path.join(self.root_path, font_family)
|
||||||
font = ImageFont.truetype(font_path, font_size)
|
font = ImageFont.truetype(font_path, font_size)
|
||||||
except Exception:
|
except Exception:
|
||||||
errorLogging()
|
errorLogging()
|
||||||
font_path = os_path.join(os_path.dirname(__file__), "..", "..", "..", "fonts", f"{font_family}.ttf")
|
font_path = os_path.join(os_path.dirname(__file__), "..", "..", "..", "fonts", font_family)
|
||||||
font = ImageFont.truetype(font_path, font_size)
|
font = ImageFont.truetype(font_path, font_size)
|
||||||
|
|
||||||
text_width = draw.textlength(text, font)
|
text_width = draw.textlength(text, font)
|
||||||
@@ -172,11 +204,11 @@ class OverlayImage:
|
|||||||
draw = ImageDraw.Draw(img)
|
draw = ImageDraw.Draw(img)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
font_path = os_path.join(os_path.dirname(os_path.dirname(os_path.dirname(__file__))), "fonts", "NotoSansJP-Regular.ttf")
|
font_path = os_path.join(self.root_path, self.LANGUAGES["Default"])
|
||||||
font = ImageFont.truetype(font_path, font_size)
|
font = ImageFont.truetype(font_path, font_size)
|
||||||
except Exception:
|
except Exception:
|
||||||
errorLogging()
|
errorLogging()
|
||||||
font_path = os_path.join(os_path.dirname(__file__), "..", "..", "..", "fonts", "NotoSansJP-Regular.ttf")
|
font_path = os_path.join(os_path.dirname(__file__), "..", "..", "..", "fonts", self.LANGUAGES["Default"])
|
||||||
font = ImageFont.truetype(font_path, font_size)
|
font = ImageFont.truetype(font_path, font_size)
|
||||||
|
|
||||||
text_height = font_size + ui_padding
|
text_height = font_size + ui_padding
|
||||||
@@ -191,17 +223,37 @@ class OverlayImage:
|
|||||||
draw.text((text_x, text_y), text, text_color, anchor=anchor, stroke_width=0, font=font)
|
draw.text((text_x, text_y), text, text_color, anchor=anchor, stroke_width=0, font=font)
|
||||||
return img
|
return img
|
||||||
|
|
||||||
def createTextboxLargeLog(self, message_type:str, message:str, your_language:str, translation:str, target_language:str, date_time:str) -> Image:
|
def createTextboxLargeLog(self, message_type: str, message: str = None, your_language: str = None, translation: list = [], target_language: list = [], date_time: str = None) -> Image:
|
||||||
message_type_img = self.createTextImageMessageType(message_type, date_time)
|
# テキスト画像のリストを作成
|
||||||
if translation and target_language:
|
images = [self.createTextImageMessageType(message_type, date_time)]
|
||||||
img = self.createTextImageLargeLog(message_type, "small", message, your_language)
|
|
||||||
translation_img = self.createTextImageLargeLog(message_type, "large", translation, target_language)
|
|
||||||
img = self.concatenateImagesVertically(img, translation_img)
|
|
||||||
else:
|
|
||||||
img = self.createTextImageLargeLog(message_type, "large", message, your_language)
|
|
||||||
return self.concatenateImagesVertically(message_type_img, img)
|
|
||||||
|
|
||||||
def createOverlayImageLargeLog(self, message_type:str, message:str, your_language:str, translation:str="", target_language:str=None) -> Image:
|
# 翻訳がある場合
|
||||||
|
if translation and target_language:
|
||||||
|
# 元のメッセージがある場合は小さいサイズで追加
|
||||||
|
if message is not None:
|
||||||
|
images.append(
|
||||||
|
self.createTextImageLargeLog(message_type, "small", message, your_language)
|
||||||
|
)
|
||||||
|
|
||||||
|
# 翻訳をすべて大きいサイズで追加
|
||||||
|
for trans, lang in zip(translation, target_language):
|
||||||
|
images.append(
|
||||||
|
self.createTextImageLargeLog(message_type, "large", trans, lang)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
# 翻訳がない場合は元のメッセージのみ
|
||||||
|
images.append(
|
||||||
|
self.createTextImageLargeLog(message_type, "large", message, your_language)
|
||||||
|
)
|
||||||
|
|
||||||
|
# すべてのテキスト画像を縦に結合
|
||||||
|
combined_img = images[0]
|
||||||
|
for img in images[1:]:
|
||||||
|
combined_img = self.concatenateImagesVertically(combined_img, img)
|
||||||
|
|
||||||
|
return combined_img
|
||||||
|
|
||||||
|
def createOverlayImageLargeLog(self, message_type:str, message:str=None, your_language:str=None, translation:list=[], target_language:list=[]) -> Image:
|
||||||
ui_color = self.getUiColorLargeLog()
|
ui_color = self.getUiColorLargeLog()
|
||||||
background_color = ui_color["background_color"]
|
background_color = ui_color["background_color"]
|
||||||
background_outline_color = ui_color["background_outline_color"]
|
background_outline_color = ui_color["background_outline_color"]
|
||||||
@@ -242,7 +294,8 @@ class OverlayImage:
|
|||||||
background = Image.new("RGBA", (width, height), (0, 0, 0, 0))
|
background = Image.new("RGBA", (width, height), (0, 0, 0, 0))
|
||||||
draw = ImageDraw.Draw(background)
|
draw = ImageDraw.Draw(background)
|
||||||
draw.rounded_rectangle([(0, 0), (width, height)], radius=ui_radius, fill=background_color, outline=background_outline_color, width=5)
|
draw.rounded_rectangle([(0, 0), (width, height)], radius=ui_radius, fill=background_color, outline=background_outline_color, width=5)
|
||||||
return Image.alpha_composite(background, img)
|
img = Image.alpha_composite(background, img)
|
||||||
|
return img
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
overlay = OverlayImage()
|
overlay = OverlayImage()
|
||||||
|
|||||||
Reference in New Issue
Block a user