未验证 提交 49d1a595 编写于 作者: livingbody's avatar livingbody 提交者: GitHub

upgrade pillow to 10.0.0 (#10405)

上级 cd5d0134
...@@ -23,7 +23,8 @@ class StdTextDrawer(object): ...@@ -23,7 +23,8 @@ class StdTextDrawer(object):
def get_valid_height(self, font_path): def get_valid_height(self, font_path):
font = ImageFont.truetype(font_path, self.height - 4) font = ImageFont.truetype(font_path, self.height - 4)
_, font_height = font.getsize(self.char_list) left, top, right, bottom = font.getbbox(self.char_list)
_, font_height = right - left, bottom - top
if font_height <= self.height - 4: if font_height <= self.height - 4:
return self.height - 4 return self.height - 4
else: else:
......
...@@ -55,7 +55,8 @@ def get_horizontal_text_picture(image_file, chars, fonts_list, cf): ...@@ -55,7 +55,8 @@ def get_horizontal_text_picture(image_file, chars, fonts_list, cf):
ch_w = [] ch_w = []
ch_h = [] ch_h = []
for ch in chars: for ch in chars:
wt, ht = font.getsize(ch) left, top, right, bottom = font.getbbox(ch)
wt, ht = right - left, bottom - top
ch_w.append(wt) ch_w.append(wt)
ch_h.append(ht) ch_h.append(ht)
f_w = sum(ch_w) f_w = sum(ch_w)
...@@ -101,7 +102,8 @@ def get_vertical_text_picture(image_file, chars, fonts_list, cf): ...@@ -101,7 +102,8 @@ def get_vertical_text_picture(image_file, chars, fonts_list, cf):
ch_w = [] ch_w = []
ch_h = [] ch_h = []
for ch in chars: for ch in chars:
wt, ht = font.getsize(ch) left, top, right, bottom = font.getbbox(ch)
wt, ht = right - left, bottom - top
ch_w.append(wt) ch_w.append(wt)
ch_h.append(ht) ch_h.append(ht)
f_w = max(ch_w) f_w = max(ch_w)
......
...@@ -406,7 +406,7 @@ class GrayRecResizeImg(object): ...@@ -406,7 +406,7 @@ class GrayRecResizeImg(object):
def __init__(self, def __init__(self,
image_shape, image_shape,
resize_type, resize_type,
inter_type='Image.ANTIALIAS', inter_type='Image.LANCZOS',
scale=True, scale=True,
padding=False, padding=False,
**kwargs): **kwargs):
......
...@@ -62,8 +62,8 @@ def draw_box_txt(bbox, text, draw, font, font_size, color): ...@@ -62,8 +62,8 @@ def draw_box_txt(bbox, text, draw, font, font_size, color):
draw.rectangle(bbox, fill=color) draw.rectangle(bbox, fill=color)
# draw ocr results # draw ocr results
tw = font.getsize(text)[0] left, top, right, bottom = font.getbbox(text)
th = font.getsize(text)[1] tw, th = right - left, bottom - top
start_y = max(0, bbox[0][1] - th) start_y = max(0, bbox[0][1] - th)
draw.rectangle( draw.rectangle(
[(bbox[0][0] + 1, start_y), (bbox[0][0] + tw + 1, start_y + th)], [(bbox[0][0] + 1, start_y), (bbox[0][0] + tw + 1, start_y + th)],
......
...@@ -132,7 +132,8 @@ def draw_structure_result(image, result, font_path): ...@@ -132,7 +132,8 @@ def draw_structure_result(image, result, font_path):
[(box_layout[0], box_layout[1]), (box_layout[2], box_layout[3])], [(box_layout[0], box_layout[1]), (box_layout[2], box_layout[3])],
outline=box_color, outline=box_color,
width=3) width=3)
text_w, text_h = font.getsize(region['type']) left, top, right, bottom = font.getbbox(region['type'])
text_w, text_h = right - left, bottom - top
draw_layout.rectangle( draw_layout.rectangle(
[(box_layout[0], box_layout[1]), [(box_layout[0], box_layout[1]),
(box_layout[0] + text_w, box_layout[1] + text_h)], (box_layout[0] + text_w, box_layout[1] + text_h)],
......
...@@ -15,4 +15,4 @@ premailer ...@@ -15,4 +15,4 @@ premailer
openpyxl openpyxl
attrdict attrdict
PyMuPDF<1.21.0 PyMuPDF<1.21.0
Pillow<=9.5.0 Pillow>=10.0.0
...@@ -156,7 +156,7 @@ class TextRecognizer(object): ...@@ -156,7 +156,7 @@ class TextRecognizer(object):
if self.rec_algorithm == 'ViTSTR': if self.rec_algorithm == 'ViTSTR':
img = image_pil.resize([imgW, imgH], Image.BICUBIC) img = image_pil.resize([imgW, imgH], Image.BICUBIC)
else: else:
img = image_pil.resize([imgW, imgH], Image.ANTIALIAS) img = image_pil.resize([imgW, imgH], Image.LANCZOS)
img = np.array(img) img = np.array(img)
norm_img = np.expand_dims(img, -1) norm_img = np.expand_dims(img, -1)
norm_img = norm_img.transpose((2, 0, 1)) norm_img = norm_img.transpose((2, 0, 1))
......
...@@ -471,7 +471,7 @@ def draw_box_txt_fine(img_size, box, txt, font_path="./doc/fonts/simfang.ttf"): ...@@ -471,7 +471,7 @@ def draw_box_txt_fine(img_size, box, txt, font_path="./doc/fonts/simfang.ttf"):
def create_font(txt, sz, font_path="./doc/fonts/simfang.ttf"): def create_font(txt, sz, font_path="./doc/fonts/simfang.ttf"):
font_size = int(sz[1] * 0.99) font_size = int(sz[1] * 0.99)
font = ImageFont.truetype(font_path, font_size, encoding="utf-8") font = ImageFont.truetype(font_path, font_size, encoding="utf-8")
length = font.getsize(txt)[0] length = font.getlength(txt)
if length > sz[0]: if length > sz[0]:
font_size = int(font_size * sz[0] / length) font_size = int(font_size * sz[0] / length)
font = ImageFont.truetype(font_path, font_size, encoding="utf-8") font = ImageFont.truetype(font_path, font_size, encoding="utf-8")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册