From 3a643710caca5eeb5b01e3aac70dc42bff19ee6d Mon Sep 17 00:00:00 2001 From: Miguel Angel Reina Ortega <miguelangel.reinaortega@etsi.org> Date: Thu, 30 Nov 2023 17:18:49 +0100 Subject: [PATCH] Adding pure python emf to png converter --- requirements.txt | 1 + spec2md.py | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/requirements.txt b/requirements.txt index e3311b2..50a2a25 100644 --- a/requirements.txt +++ b/requirements.txt @@ -20,3 +20,4 @@ rich==13.7.0 # via oneM2M-spec-2-MD-converter (setup.py) typing-extensions==4.8.0 # via python-docx +pillow==10.1.0 diff --git a/spec2md.py b/spec2md.py index b8a1da7..dc24414 100644 --- a/spec2md.py +++ b/spec2md.py @@ -26,6 +26,8 @@ from rich import inspect import configparser, zipfile from lxml import etree as ET +from PIL import Image + class Style(IntEnum): example = auto() image = auto() @@ -620,6 +622,7 @@ def processDocuments(documents:list[str], outDirectory:str, skipImageConversion: elif style in docConfig.tablecaption: lines.append('') caption = replaceNL(text).strip() + caption = replaceNL(text).strip() anchor = f'<a name="table_{caption[6:].split(":")[0].strip()}"></a>' if caption.startswith('Table ') and ':' in caption else '' lines.append(f'**{caption}**{anchor}') @@ -824,10 +827,12 @@ def processDocuments(documents:list[str], outDirectory:str, skipImageConversion: cmd = converter cmd = cmd.replace('{infile}', fn).replace('{outdir}', _t) _print(f'Converting EMF file: {fn} to "{format}"', highlight = False) - if (res := subprocess.run(cmd, shell = True, capture_output = True)).returncode != 0: - _print(f'[red]Error running command: {res.stderr.decode("utf-8")}') - _print(f'[red]Please check the configuration file -> section "\[media]" for the converter command: {converter}') - break + + convert(fn, fn[:-4]) + #if (res := subprocess.run(cmd, shell = True, capture_output = True)).returncode != 0: + # _print(f'[red]Error running command: {res.stderr.decode("utf-8")}') + # _print(f'[red]Please check the configuration file -> section "\[media]" for the converter command: {converter}') + # break if not skipImageConversion: if docConfig.emfConverterPng: @@ -842,6 +847,10 @@ def processDocuments(documents:list[str], outDirectory:str, skipImageConversion: progress.stop() +def convert(input:str, output_name:str): + + name=output_name+".png" + Image.open(input).save(str(name)) if __name__ == '__main__': -- GitLab