mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-06 20:29:59 +08:00
Update img_utils.py
This commit is contained in:
@@ -2,6 +2,7 @@ import os
|
|||||||
from configs.path_config import IMAGE_PATH, TXT_PATH, TTF_PATH
|
from configs.path_config import IMAGE_PATH, TXT_PATH, TTF_PATH
|
||||||
from PIL import Image, ImageFile, ImageDraw, ImageFont
|
from PIL import Image, ImageFile, ImageDraw, ImageFont
|
||||||
import cv2
|
import cv2
|
||||||
|
from typing import Tuple
|
||||||
import imagehash
|
import imagehash
|
||||||
import base64
|
import base64
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
@@ -223,6 +224,18 @@ class CreateImg:
|
|||||||
self.current_w += self.img_w
|
self.current_w += self.img_w
|
||||||
return self.markImg
|
return self.markImg
|
||||||
|
|
||||||
|
def crop(self, box: Tuple[int, int, int, int]):
|
||||||
|
"""
|
||||||
|
说明:
|
||||||
|
裁剪图片
|
||||||
|
参数:
|
||||||
|
:param box: 左上角坐标,右下角坐标 (left, upper, right, lower)
|
||||||
|
"""
|
||||||
|
self.markImg = self.markImg.crop(box)
|
||||||
|
self.w, self.h = self.markImg.size
|
||||||
|
self.size = self.w, self.h
|
||||||
|
self.draw = ImageDraw.Draw(self.markImg)
|
||||||
|
|
||||||
# 获取文字大小
|
# 获取文字大小
|
||||||
def getsize(self, msg):
|
def getsize(self, msg):
|
||||||
return self.ttfont.getsize(msg)
|
return self.ttfont.getsize(msg)
|
||||||
|
|||||||
Reference in New Issue
Block a user