def apply_left(self, img: PILImage, text_bbox: BBox) -> Tuple[PILImage, BBox]: in_offset, thickness, out_offset = self._get_lr_param() new_w = img.width + thickness + in_offset + out_offset new_h = img.height new_img = transparent_img((new_w, new_h)) new_img.paste(img, (thickness + in_offset + out_offset, 0)) draw = ImageDraw.Draw(new_img) text_bbox.offset_(text_bbox.right_top, (new_w, 0)) text_bbox.left -= in_offset draw.line( list(text_bbox.left_top) + list(text_bbox.left_bottom), fill=self._get_line_color(img, text_bbox), width=thickness, ) text_bbox.left -= thickness text_bbox.left -= out_offset return new_img, text_bbox
def test_offset(): bbox1 = BBox(0, 0, 100, 32) bbox2 = BBox(0, 0, 50, 16) bbox2.offset_(bbox2.left_cnt, bbox1.right_cnt) assert bbox2 == BBox(100, 8, 150, 24)