项目基础模块代码
This commit is contained in:
@ -7,7 +7,7 @@ def create_folder(*path):
|
||||
"""根据路径创建文件夹"""
|
||||
folder_path = os.path.join(*path)
|
||||
try:
|
||||
os.makedirs(path, exist_ok=True)
|
||||
os.makedirs(folder_path, exist_ok=True)
|
||||
except Exception as e:
|
||||
print(f"创建文件夹时错误: {e}")
|
||||
|
||||
@ -20,6 +20,8 @@ def save_images(*path, file: UploadFile):
|
||||
:return:
|
||||
"""
|
||||
save_path = os.path.join(*path, file.filename)
|
||||
|
||||
os.makedirs(os.path.dirname(save_path), exist_ok=True)
|
||||
with open(save_path, "wb") as f:
|
||||
for line in file.file:
|
||||
f.write(line)
|
||||
@ -38,6 +40,6 @@ def create_thumbnail(input_image_path, out_image_path, size=(116, 70)):
|
||||
# 使用thumbnail方法生成缩略图,参数size指定缩略图的最大尺寸
|
||||
# 注意:thumbnail方法会保持图片的宽高比不变
|
||||
image.thumbnail(size)
|
||||
|
||||
os.makedirs(os.path.dirname(out_image_path), exist_ok=True)
|
||||
# 保存生成的缩略图
|
||||
image.save(out_image_path, 'JPEG')
|
||||
|
Reference in New Issue
Block a user