MCPcopy Create free account
hub / github.com/Paper2Poster/Paper2Poster / wmf_to_images

Function wmf_to_images

utils/src/utils.py:182–206  ·  view source on GitHub ↗
(blob: bytes, filepath: str)

Source from the content-addressed store, hash-verified

180
181@tenacity
182def 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
209def extract_fill(shape: BaseShape):

Callers 1

from_shapeMethod · 0.90

Calls 1

runMethod · 0.45

Tested by

no test coverage detected