[Refactor] Improve overlay image creation logic for small logs and translations
This commit is contained in:
@@ -432,10 +432,22 @@ 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(
|
||||||
|
message,
|
||||||
|
language,
|
||||||
|
translation,
|
||||||
|
config.SELECTED_YOUR_LANGUAGES[config.SELECTED_TAB_NO],
|
||||||
|
)
|
||||||
model.updateOverlaySmallLog(overlay_image)
|
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:
|
||||||
|
|||||||
@@ -717,9 +717,8 @@ 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):
|
||||||
@@ -769,9 +768,9 @@ 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, your_language:str, translation:list, target_languages:dict):
|
def createOverlayImageLargeLog(self, message_type:str, message:str, your_language:str, translation:list, target_language:dict):
|
||||||
target_languages = [data["language"] for data in target_languages.values() if data["enable"] is True]
|
target_language = [data["language"] for data in target_language.values() if data["enable"] is True]
|
||||||
return self.overlay_image.createOverlayImageLargeLog(message_type, message, your_language, translation, target_languages)
|
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
|
||||||
|
|||||||
@@ -86,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"]
|
||||||
|
|
||||||
@@ -95,17 +96,40 @@ 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)
|
||||||
|
|
||||||
|
# 背景とテキストを合成
|
||||||
img = Image.alpha_composite(background, img)
|
img = Image.alpha_composite(background, img)
|
||||||
img.save("overlay_small.png")
|
|
||||||
return img
|
return img
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -271,7 +295,6 @@ class OverlayImage:
|
|||||||
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)
|
||||||
img = Image.alpha_composite(background, img)
|
img = Image.alpha_composite(background, img)
|
||||||
img.save("overlay_large.png")
|
|
||||||
return img
|
return img
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user