mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-09-29 00:32:06 +08:00
update image_utils
This commit is contained in:
+12
-7
@@ -14,6 +14,8 @@ from imagehash import ImageHash
|
||||
from matplotlib import pyplot as plt
|
||||
from PIL import Image, ImageDraw, ImageFile, ImageFilter, ImageFont
|
||||
|
||||
from services import logger
|
||||
|
||||
ImageFile.LOAD_TRUNCATED_IMAGES = True
|
||||
Image.MAX_IMAGE_PIXELS = None
|
||||
|
||||
@@ -209,13 +211,16 @@ class BuildImage:
|
||||
(self.w, self.h), Image.ANTIALIAS
|
||||
)
|
||||
if is_alpha:
|
||||
array = self.markImg.load()
|
||||
for i in range(w):
|
||||
for j in range(h):
|
||||
pos = array[i, j]
|
||||
is_edit = sum([1 for x in pos[0:3] if x > 240]) == 3
|
||||
if is_edit:
|
||||
array[i, j] = (255, 255, 255, 0)
|
||||
try:
|
||||
array = self.markImg.load()
|
||||
for i in range(w):
|
||||
for j in range(h):
|
||||
pos = array[i, j]
|
||||
is_edit = sum([1 for x in pos[0:3] if x > 240]) == 3
|
||||
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.size = self.w, self.h
|
||||
if plain_text:
|
||||
|
||||
Reference in New Issue
Block a user