Skip to content

Commit

Permalink
Update img_utils.py
Browse files Browse the repository at this point in the history
  • Loading branch information
HibiKier committed Jul 27, 2021
1 parent 0dfca7e commit edbbcec
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions utils/img_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from configs.path_config import IMAGE_PATH, TXT_PATH, TTF_PATH
from PIL import Image, ImageFile, ImageDraw, ImageFont
import cv2
from typing import Tuple
import imagehash
import base64
from io import BytesIO
Expand Down Expand Up @@ -223,6 +224,18 @@ def paste(self, img, pos=None, alpha=False):
self.current_w += self.img_w
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):
return self.ttfont.getsize(msg)
Expand Down

0 comments on commit edbbcec

Please sign in to comment.