Process image and return draw.io XML string. Args: image_path: Input image path. Returns: draw.io XML string.
(self, image_path: str)
| 90 | return self._pix2text_ocr |
| 91 | |
| 92 | def process(self, image_path: str) -> str: |
| 93 | """ |
| 94 | Process image and return draw.io XML string. |
| 95 | |
| 96 | Args: |
| 97 | image_path: Input image path. |
| 98 | Returns: |
| 99 | draw.io XML string. |
| 100 | """ |
| 101 | image_path = Path(image_path) |
| 102 | |
| 103 | with Image.open(image_path) as img: |
| 104 | image_width, image_height = img.size |
| 105 | |
| 106 | text_blocks = self.process_image(str(image_path)) |
| 107 | |
| 108 | generator = MxGraphXMLGenerator( |
| 109 | diagram_name=image_path.stem, |
| 110 | page_width=image_width, |
| 111 | page_height=image_height |
| 112 | ) |
| 113 | |
| 114 | text_cells = [] |
| 115 | for block in text_blocks: |
| 116 | geo = block["geometry"] |
| 117 | cell = generator.create_text_cell( |
| 118 | text=block["text"], |
| 119 | x=geo["x"], |
| 120 | y=geo["y"], |
| 121 | width=max(geo["width"], 20), |
| 122 | height=max(geo["height"], 10), |
| 123 | font_size=block.get("font_size", 12), |
| 124 | is_latex=block.get("is_latex", False), |
| 125 | rotation=geo.get("rotation", 0), |
| 126 | font_weight=block.get("font_weight"), |
| 127 | font_style=block.get("font_style"), |
| 128 | font_color=block.get("font_color"), |
| 129 | font_family=block.get("font_family") |
| 130 | ) |
| 131 | text_cells.append(cell) |
| 132 | |
| 133 | return generator.generate_xml(text_cells) |
| 134 | |
| 135 | def process_image(self, image_path: str) -> List[Dict[str, Any]]: |
| 136 | """Process image and return list of text blocks.""" |
no test coverage detected