Skip to content

Commit

Permalink
upgrade pillow to 10.0.0 (#10405)
Browse files Browse the repository at this point in the history
  • Loading branch information
livingbody authored Jul 17, 2023
1 parent cd5d013 commit 49d1a59
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 10 deletions.
3 changes: 2 additions & 1 deletion StyleText/engine/text_drawers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def load_fonts(self, fonts_config):

def get_valid_height(self, font_path):
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:
return self.height - 4
else:
Expand Down
6 changes: 4 additions & 2 deletions applications/PCB字符识别/gen_data/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def get_horizontal_text_picture(image_file, chars, fonts_list, cf):
ch_w = []
ch_h = []
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_h.append(ht)
f_w = sum(ch_w)
Expand Down Expand Up @@ -101,7 +102,8 @@ def get_vertical_text_picture(image_file, chars, fonts_list, cf):
ch_w = []
ch_h = []
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_h.append(ht)
f_w = max(ch_w)
Expand Down
2 changes: 1 addition & 1 deletion ppocr/data/imaug/rec_img_aug.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ class GrayRecResizeImg(object):
def __init__(self,
image_shape,
resize_type,
inter_type='Image.ANTIALIAS',
inter_type='Image.LANCZOS',
scale=True,
padding=False,
**kwargs):
Expand Down
4 changes: 2 additions & 2 deletions ppocr/utils/visual.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ def draw_box_txt(bbox, text, draw, font, font_size, color):
draw.rectangle(bbox, fill=color)

# draw ocr results
tw = font.getsize(text)[0]
th = font.getsize(text)[1]
left, top, right, bottom = font.getbbox(text)
tw, th = right - left, bottom - top
start_y = max(0, bbox[0][1] - th)
draw.rectangle(
[(bbox[0][0] + 1, start_y), (bbox[0][0] + tw + 1, start_y + th)],
Expand Down
3 changes: 2 additions & 1 deletion ppstructure/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ def draw_structure_result(image, result, font_path):
[(box_layout[0], box_layout[1]), (box_layout[2], box_layout[3])],
outline=box_color,
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(
[(box_layout[0], box_layout[1]),
(box_layout[0] + text_w, box_layout[1] + text_h)],
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ premailer
openpyxl
attrdict
PyMuPDF<1.21.0
Pillow<=9.5.0
Pillow>=10.0.0
2 changes: 1 addition & 1 deletion tools/infer/predict_rec.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def resize_norm_img(self, img, max_wh_ratio):
if self.rec_algorithm == 'ViTSTR':
img = image_pil.resize([imgW, imgH], Image.BICUBIC)
else:
img = image_pil.resize([imgW, imgH], Image.ANTIALIAS)
img = image_pil.resize([imgW, imgH], Image.LANCZOS)
img = np.array(img)
norm_img = np.expand_dims(img, -1)
norm_img = norm_img.transpose((2, 0, 1))
Expand Down
2 changes: 1 addition & 1 deletion tools/infer/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
font_size = int(sz[1] * 0.99)
font = ImageFont.truetype(font_path, font_size, encoding="utf-8")
length = font.getsize(txt)[0]
length = font.getlength(txt)
if length > sz[0]:
font_size = int(font_size * sz[0] / length)
font = ImageFont.truetype(font_path, font_size, encoding="utf-8")
Expand Down

0 comments on commit 49d1a59

Please sign in to comment.