[Update] OverlayImage: Improve font loading logic with error handling for font file paths
This commit is contained in:
@@ -1136,7 +1136,6 @@ class Controller:
|
|||||||
else:
|
else:
|
||||||
raise ValueError()
|
raise ValueError()
|
||||||
except Exception:
|
except Exception:
|
||||||
errorLogging()
|
|
||||||
response = {
|
response = {
|
||||||
"status":400,
|
"status":400,
|
||||||
"result":{
|
"result":{
|
||||||
@@ -1178,7 +1177,6 @@ class Controller:
|
|||||||
else:
|
else:
|
||||||
raise ValueError()
|
raise ValueError()
|
||||||
except Exception:
|
except Exception:
|
||||||
errorLogging()
|
|
||||||
response = {
|
response = {
|
||||||
"status":400,
|
"status":400,
|
||||||
"result":{
|
"result":{
|
||||||
@@ -1203,7 +1201,6 @@ class Controller:
|
|||||||
else:
|
else:
|
||||||
raise ValueError()
|
raise ValueError()
|
||||||
except Exception:
|
except Exception:
|
||||||
errorLogging()
|
|
||||||
response = {
|
response = {
|
||||||
"status":400,
|
"status":400,
|
||||||
"result":{
|
"result":{
|
||||||
@@ -1228,7 +1225,6 @@ class Controller:
|
|||||||
else:
|
else:
|
||||||
raise ValueError()
|
raise ValueError()
|
||||||
except Exception:
|
except Exception:
|
||||||
errorLogging()
|
|
||||||
response = {
|
response = {
|
||||||
"status":400,
|
"status":400,
|
||||||
"result":{
|
"result":{
|
||||||
@@ -1319,7 +1315,6 @@ class Controller:
|
|||||||
else:
|
else:
|
||||||
raise ValueError()
|
raise ValueError()
|
||||||
except Exception:
|
except Exception:
|
||||||
errorLogging()
|
|
||||||
response = {
|
response = {
|
||||||
"status":400,
|
"status":400,
|
||||||
"result":{
|
"result":{
|
||||||
@@ -1360,7 +1355,6 @@ class Controller:
|
|||||||
else:
|
else:
|
||||||
raise ValueError()
|
raise ValueError()
|
||||||
except Exception:
|
except Exception:
|
||||||
errorLogging()
|
|
||||||
response = {
|
response = {
|
||||||
"status":400,
|
"status":400,
|
||||||
"result":{
|
"result":{
|
||||||
@@ -1385,7 +1379,6 @@ class Controller:
|
|||||||
else:
|
else:
|
||||||
raise ValueError()
|
raise ValueError()
|
||||||
except Exception:
|
except Exception:
|
||||||
errorLogging()
|
|
||||||
response = {
|
response = {
|
||||||
"status":400,
|
"status":400,
|
||||||
"result":{
|
"result":{
|
||||||
@@ -1411,7 +1404,6 @@ class Controller:
|
|||||||
else:
|
else:
|
||||||
raise ValueError()
|
raise ValueError()
|
||||||
except Exception:
|
except Exception:
|
||||||
errorLogging()
|
|
||||||
response = {
|
response = {
|
||||||
"status":400,
|
"status":400,
|
||||||
"result":{
|
"result":{
|
||||||
|
|||||||
@@ -67,9 +67,16 @@ class OverlayImage:
|
|||||||
font_path = os_path.join(self.root_path, font_family)
|
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()
|
# overlayフォルダから操作している場合
|
||||||
font_path = os_path.join(os_path.dirname(__file__), "..", "..", "..", "fonts", font_family)
|
if os_path.exists(os_path.join(os_path.dirname(__file__), "..", "..", "..", "fonts", font_family)):
|
||||||
font = ImageFont.truetype(font_path, font_size)
|
font_path = os_path.join(os_path.dirname(__file__), "..", "..", "..", "fonts", font_family)
|
||||||
|
font = ImageFont.truetype(font_path, font_size)
|
||||||
|
elif os_path.exists(os_path.join(os_path.dirname(__file__), "fonts", font_family)):
|
||||||
|
# src-pythonフォルダから操作している場合
|
||||||
|
font_path = os_path.join(os_path.dirname(__file__), "fonts", font_family)
|
||||||
|
font = ImageFont.truetype(font_path, font_size)
|
||||||
|
else:
|
||||||
|
raise FileNotFoundError(f"Font file not found: {font_family}")
|
||||||
|
|
||||||
text_width = draw.textlength(text, font)
|
text_width = draw.textlength(text, font)
|
||||||
character_width = text_width // len(text)
|
character_width = text_width // len(text)
|
||||||
@@ -171,9 +178,14 @@ class OverlayImage:
|
|||||||
font_path = os_path.join(self.root_path, font_family)
|
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()
|
if os_path.exists(os_path.join(os_path.dirname(__file__), "..", "..", "..", "fonts", font_family)):
|
||||||
font_path = os_path.join(os_path.dirname(__file__), "..", "..", "..", "fonts", font_family)
|
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)
|
||||||
|
elif os_path.exists(os_path.join(os_path.dirname(__file__), "fonts", font_family)):
|
||||||
|
font_path = os_path.join(os_path.dirname(__file__), "fonts", font_family)
|
||||||
|
font = ImageFont.truetype(font_path, font_size)
|
||||||
|
else:
|
||||||
|
raise FileNotFoundError(f"Font file not found: {font_family}")
|
||||||
|
|
||||||
# 改行を含んだtextの最大の文字数を計算する
|
# 改行を含んだtextの最大の文字数を計算する
|
||||||
text_width = max(draw.textlength(line, font) for line in text.split("\n"))
|
text_width = max(draw.textlength(line, font) for line in text.split("\n"))
|
||||||
@@ -207,9 +219,16 @@ class OverlayImage:
|
|||||||
font_path = os_path.join(self.root_path, self.LANGUAGES["Default"])
|
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()
|
# overlayフォルダから操作している場合
|
||||||
font_path = os_path.join(os_path.dirname(__file__), "..", "..", "..", "fonts", self.LANGUAGES["Default"])
|
if os_path.exists(os_path.join(os_path.dirname(__file__), "..", "..", "..", "fonts", self.LANGUAGES["Default"])):
|
||||||
font = ImageFont.truetype(font_path, font_size)
|
font_path = os_path.join(os_path.dirname(__file__), "..", "..", "..", "fonts", self.LANGUAGES["Default"])
|
||||||
|
font = ImageFont.truetype(font_path, font_size)
|
||||||
|
elif os_path.exists(os_path.join(os_path.dirname(__file__), "fonts", self.LANGUAGES["Default"])):
|
||||||
|
# src-pythonフォルダから操作している場合
|
||||||
|
font_path = os_path.join(os_path.dirname(__file__), "fonts", self.LANGUAGES["Default"])
|
||||||
|
font = ImageFont.truetype(font_path, font_size)
|
||||||
|
else:
|
||||||
|
raise FileNotFoundError(f"Font file not found: {self.LANGUAGES['Default']}")
|
||||||
|
|
||||||
text_height = font_size + ui_padding
|
text_height = font_size + ui_padding
|
||||||
text_width = draw.textlength(date_time, font)
|
text_width = draw.textlength(date_time, font)
|
||||||
|
|||||||
Reference in New Issue
Block a user