update image_utils

This commit is contained in:
HibiKier 2022-06-18 15:09:55 +08:00
parent 007823d6b2
commit 903b5b88a7
2 changed files with 13 additions and 7 deletions

View File

@ -247,6 +247,7 @@ __Docker 最新版本由 [Sakuracio](https://github.com/Sakuracio) 提供__
* 修复webui中plugins2setting修改时会改变plugins2setting.cmd为字符串 * 修复webui中plugins2setting修改时会改变plugins2setting.cmd为字符串
* 修复昵称系统`BLACK_WORD`为空时造成报错 * 修复昵称系统`BLACK_WORD`为空时造成报错
* 修复特殊头像时背景透明化出错
* 优化webUI当有插件出错时不会影响其他插件显示 * 优化webUI当有插件出错时不会影响其他插件显示
* 优化Config类型注释 [@pull/830](https://github.com/HibiKier/zhenxun_bot/pull/830) * 优化Config类型注释 [@pull/830](https://github.com/HibiKier/zhenxun_bot/pull/830)
* 优化browser * 优化browser

View File

@ -14,6 +14,8 @@ from imagehash import ImageHash
from matplotlib import pyplot as plt from matplotlib import pyplot as plt
from PIL import Image, ImageDraw, ImageFile, ImageFilter, ImageFont from PIL import Image, ImageDraw, ImageFile, ImageFilter, ImageFont
from services import logger
ImageFile.LOAD_TRUNCATED_IMAGES = True ImageFile.LOAD_TRUNCATED_IMAGES = True
Image.MAX_IMAGE_PIXELS = None Image.MAX_IMAGE_PIXELS = None
@ -209,13 +211,16 @@ class BuildImage:
(self.w, self.h), Image.ANTIALIAS (self.w, self.h), Image.ANTIALIAS
) )
if is_alpha: if is_alpha:
array = self.markImg.load() try:
for i in range(w): array = self.markImg.load()
for j in range(h): for i in range(w):
pos = array[i, j] for j in range(h):
is_edit = sum([1 for x in pos[0:3] if x > 240]) == 3 pos = array[i, j]
if is_edit: is_edit = sum([1 for x in pos[0:3] if x > 240]) == 3
array[i, j] = (255, 255, 255, 0) if is_edit:
array[i, j] = (255, 255, 255, 0)
except Exception as e:
logger.warning(f"背景透明化发生错误..{type(e)}{e}")
self.draw = ImageDraw.Draw(self.markImg) self.draw = ImageDraw.Draw(self.markImg)
self.size = self.w, self.h self.size = self.w, self.h
if plain_text: if plain_text: