fix(pil): 补充修复剩余 PIL Image 资源泄漏
覆盖 14 个文件中的 Image.open() 未正确关闭问题: - fansclub_handler: 5 处(pic/pic_rgb/img 未 close) - image_ops: 2 处(crop 后 pic 未 close) - douyin_popups: 2 处(pic.convert 重赋值泄漏原始句柄) - douyin_fudai: 1 处(open().convert() 链式调用泄漏) - douyin_robot: 2 处(同上) - save_files/direct_attend/finder/stage/find_open/detail/_common/ocr_preprocess: 各 1-2 处 统一修复模式:分离 open 与 convert,try/finally 确保原始句柄关闭。 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c3746b0207
commit
bb90e2983f
14 files changed
+370
-283
No files matched your search
@@ -32,10 +32,13 @@ def preprocess_for_ocr(analyser: Any, cut_pic_name: str) -> str:
|
||||
try:
|
||||
if not os.path.exists(src):
|
||||
return cut_pic_name
|
||||
img = Image.open(src)
|
||||
img.load()
|
||||
# 转灰度
|
||||
img = img.convert("L")
|
||||
_raw = Image.open(src)
|
||||
try:
|
||||
_raw.load()
|
||||
# 转灰度
|
||||
img = _raw.convert("L")
|
||||
finally:
|
||||
_raw.close()
|
||||
# 放大两倍(Lanczos)
|
||||
img = img.resize((img.width * 2, img.height * 2), Image.LANCZOS)
|
||||
# 自动对比并锐化
|
||||
|
||||
Reference in new issue
Block a user