优化rmbg抠图服务:改用WebP格式减小文件体积并增加超时时间

This commit is contained in:
jingrow 2025-12-07 06:13:23 +08:00
parent 46845e5f57
commit cd2a6ea74c
2 changed files with 3 additions and 3 deletions

View File

@ -357,10 +357,10 @@ class RmbgService:
def save_image_to_file(self, image):
"""保存图片到文件并返回URL"""
filename = f"rmbg_{uuid.uuid4().hex[:10]}.png"
filename = f"rmbg_{uuid.uuid4().hex[:10]}.webp"
file_path = os.path.join(self.save_dir, filename)
image.save(file_path, format="PNG", optimize=False, compress_level=1)
image.save(file_path, format="WEBP", quality=85, method=6)
image_url = f"{self.download_url}/{filename}"
return image_url

View File

@ -36,7 +36,7 @@ class Settings(BaseSettings):
# 队列聚合配置方案B批处理+队列模式)
batch_collect_interval: float = 0.05 # 批处理收集间隔50ms收集一次平衡延迟和吞吐量
batch_collect_timeout: float = 0.5 # 批处理收集超时即使未满batch_size500ms后也处理
request_timeout: float = 30.0 # 单个请求超时时间(秒)
request_timeout: float = 60.0 # 单个请求超时时间(秒)
enable_queue_batch: bool = True # 是否启用队列批处理模式(推荐开启)
class Config: