| 180 | |
| 181 | @tenacity |
| 182 | def wmf_to_images(blob: bytes, filepath: str): |
| 183 | if not filepath.endswith(".jpg"): |
| 184 | raise ValueError("filepath must end with .jpg") |
| 185 | dirname = os.path.dirname(filepath) |
| 186 | basename = os.path.basename(filepath).removesuffix(".jpg") |
| 187 | with tempfile.TemporaryDirectory() as temp_dir: |
| 188 | with open(pjoin(temp_dir, f"{basename}.wmf"), "wb") as f: |
| 189 | f.write(blob) |
| 190 | # Create unique user installation directory for LibreOffice to avoid concurrency issues |
| 191 | with tempfile.TemporaryDirectory() as user_install_dir: |
| 192 | command_list = [ |
| 193 | "soffice", |
| 194 | "--headless", |
| 195 | "--norestore", |
| 196 | "--nolockcheck", |
| 197 | f"-env:UserInstallation=file://{user_install_dir}", |
| 198 | "--convert-to", |
| 199 | "jpg", |
| 200 | pjoin(temp_dir, f"{basename}.wmf"), |
| 201 | "--outdir", |
| 202 | dirname, |
| 203 | ] |
| 204 | subprocess.run(command_list, check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) |
| 205 | |
| 206 | assert pexists(filepath), f"File {filepath} does not exist" |
| 207 | |
| 208 | |
| 209 | def extract_fill(shape: BaseShape): |