diff --git a/api/contents.py b/api/contents.py index 4a3e7f2..9e4e1f3 100644 --- a/api/contents.py +++ b/api/contents.py @@ -357,8 +357,15 @@ def convert_to_binary_data(image_path: str, width: int = 400, height: int = 300, 二进制数据 """ try: - # 动态导入image_converter模块 - spec = importlib.util.spec_from_file_location("image_converter", "/Users/jeremygan/Desktop/python_dev/luna2025/tool/image_converter.py") + # 动态导入image_converter模块 - 使用相对路径 + import os + # 获取当前文件的目录 + current_dir = os.path.dirname(os.path.abspath(__file__)) + # 构建到tool目录的路径 + tool_dir = os.path.join(current_dir, "..", "tool") + image_converter_path = os.path.join(tool_dir, "image_converter.py") + # 导入模块 + spec = importlib.util.spec_from_file_location("image_converter", image_converter_path) image_converter = importlib.util.module_from_spec(spec) spec.loader.exec_module(image_converter)