def __init__(self, char_obj_list: List[CharImg], text_img_output_dir, text_img_info_output_dir, orientation, align_mode, img: Image.Image = None, img_path: str = None, **kwargs ): tmp_list = [] for item in char_obj_list: if isinstance(item, dict): tmp_list.append(CharImg(**item)) if tmp_list: char_obj_list = tmp_list self.char_obj_list = char_obj_list self.text = "".join([char_obj.char for char_obj in self.char_obj_list]) self.text_img_output_dir = text_img_output_dir self.text_img_info_output_dir = text_img_info_output_dir self.orientation = orientation self.align_mode = align_mode if img_path: self.img_name = img_path.split(os.sep)[-1] self.name = self.img_name.split('.')[0] self.img_path = img_path self.img = load_img(self.img_path) else: self.name = self._gen_name(align_mode, orientation) self.img_name = self.name + ".png" self.img_path = os.path.join(text_img_output_dir, self.img_name) self.img = img
def gen_batch_char_obj(text, color, font_size, border_width=0, border_color=(0, 0, 0, 0)) -> List[CharImg]: """ 生成一批CharImg对象 :param text: :param color: :param font_size: :param border_width: :param border_color: :return: """ char_obj_list = [] for char in text: char_obj_list.append( CharImg(char, font_size=font_size, color=color, border_width=border_width, border_color=border_color)) return char_obj_list