Skip to content

Commit

Permalink
fix: 处理图像报错
Browse files Browse the repository at this point in the history
  • Loading branch information
hanxi committed Dec 22, 2024
1 parent b37b6fd commit 617a961
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions xiaomusic/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,14 +643,19 @@ def _save_picture(picture_data, save_root, file_path):
try:
_resize_save_image(picture_data, picture_path)
except Exception as e:
log.exception(f"Error _resize_save_image: {e}")
log.warning(f"Error _resize_save_image: {e}")
return picture_path


def _resize_save_image(image_bytes, save_path, max_size=300):
# 将 bytes 转换为 PIL Image 对象
image = Image.open(io.BytesIO(image_bytes))
image = image.convert("RGB")
image = None
try:
image = Image.open(io.BytesIO(image_bytes))
image = image.convert("RGB")
except Exception as e:
log.warning(f"Error _resize_save_image: {e}")
return

# 获取原始尺寸
original_width, original_height = image.size
Expand Down

0 comments on commit 617a961

Please sign in to comment.