From bfa1f824ceded1f6f436dd03f906c1215f88e1d9 Mon Sep 17 00:00:00 2001 From: Francois Pelletier Date: Sun, 1 Jan 2023 14:16:56 -0500 Subject: [PATCH] =?UTF-8?q?changements=20pour=20flexibilit=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- install.sh | 2 ++ main.py | 14 +++++++------ styles/missioncyber/instagram/header.tex | 6 +++++- styles/missioncyber/linkedin/header.tex | 7 ++++++- styles/missioncyber/pinterest/header.tex | 6 +++++- test_main.http | 25 ++++++++++++++++++++++-- 6 files changed, 49 insertions(+), 11 deletions(-) create mode 100644 install.sh diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..498c20a --- /dev/null +++ b/install.sh @@ -0,0 +1,2 @@ +#!/bin/sh +pip install -r requirements.txt diff --git a/main.py b/main.py index 3aa2dfa..51fe7fc 100644 --- a/main.py +++ b/main.py @@ -25,9 +25,10 @@ class DocumentSpecs(BaseModel): paperwidth: int paperheight: int margin: int + vmargin: int extension: str -def convert_pdf_jpg(filename, output_path, resolution=300): +def convert_pdf(filename, filetype, output_path, resolution=300): """ Convert a PDF into images. All the pages will give a single png file with format: @@ -39,12 +40,12 @@ def convert_pdf_jpg(filename, output_path, resolution=300): all_pages = Image(filename=filename, resolution=resolution) for i, page in enumerate(all_pages.sequence): with Image(page) as img: - img.format = 'jpg' + img.format = filetype img.background_color = Color('black') #img.alpha_channel = 'remove' image_filename = os.path.splitext(os.path.basename(filename))[0] - image_filename = '{}-{}.jpg'.format(image_filename, i) + image_filename = f'{image_filename}-{i}.{filetype}' image_filename = os.path.join(output_path, image_filename) img.save(filename=image_filename) @@ -70,7 +71,8 @@ async def generer(specs: DocumentSpecs): '-V',f'fontsize={specs.fontsize}pt', '-V',f'geometry:paperwidth={specs.paperwidth/300}in', '-V',f'geometry:paperheight={specs.paperheight/300}in', - '-V',f'geometry:margin={specs.margin/300}in' + '-V',f'geometry:margin={specs.margin/300}in', + '-V',f'geometry:vmargin={specs.vmargin/300}in' ] try: logging.info("Dossier courant = " + os.getcwd()) @@ -89,13 +91,13 @@ async def generer(specs: DocumentSpecs): logging.exception(rerr) except OSError as oerr: logging.exception(oerr) - if specs.extension=="zip": + if specs.extension in ["png","jpg"]: zip_filename = os.path.splitext(os.path.basename(output_file))[0] png_output_dir = "./png_output" if not os.path.exists(png_output_dir): os.mkdir(png_output_dir) try: - convert_pdf_jpg(output_file, png_output_dir, resolution=300) + convert_pdf(output_file, specs.extension, png_output_dir, resolution=300) shutil.make_archive(zip_filename, 'zip', png_output_dir) shutil.rmtree(png_output_dir) except Exception as e: diff --git a/styles/missioncyber/instagram/header.tex b/styles/missioncyber/instagram/header.tex index 386faa0..876b1ef 100644 --- a/styles/missioncyber/instagram/header.tex +++ b/styles/missioncyber/instagram/header.tex @@ -56,4 +56,8 @@ \setsansfont[Path=font/GlacialIndifference/]{GlacialIndifference-Regular.otf} \setmonofont[Path=font/SourceCodePro/]{SourceCodePro-Regular.ttf} -\usepackage{emoji} \ No newline at end of file +\usepackage{emoji} + +\hyphenpenalty=10000 +\hbadness=10000 +\centering diff --git a/styles/missioncyber/linkedin/header.tex b/styles/missioncyber/linkedin/header.tex index cd1c6f1..6d2d4ae 100644 --- a/styles/missioncyber/linkedin/header.tex +++ b/styles/missioncyber/linkedin/header.tex @@ -50,4 +50,9 @@ \setsansfont[Path=font/GlacialIndifference/]{GlacialIndifference-Regular.otf} \setmonofont[Path=font/SourceCodePro/]{SourceCodePro-Regular.ttf} -\usepackage{emoji} \ No newline at end of file +\usepackage{emoji} + +\hyphenpenalty=10000 +\hbadness=10000 +\centering + diff --git a/styles/missioncyber/pinterest/header.tex b/styles/missioncyber/pinterest/header.tex index 399988b..3f03866 100644 --- a/styles/missioncyber/pinterest/header.tex +++ b/styles/missioncyber/pinterest/header.tex @@ -50,4 +50,8 @@ \setsansfont[Path=font/GlacialIndifference/]{GlacialIndifference-Regular.otf} \setmonofont[Path=font/SourceCodePro/]{SourceCodePro-Regular.ttf} -\usepackage{emoji} \ No newline at end of file +\usepackage{emoji} + +\hyphenpenalty=10000 +\hbadness=10000 +\centering \ No newline at end of file diff --git a/test_main.http b/test_main.http index 7c9fa77..7fc0f39 100644 --- a/test_main.http +++ b/test_main.http @@ -15,7 +15,7 @@ Accept: application/zip "paperwidth": 1080, "paperheight": 1920, "margin": 180, - "extension": "zip" + "extension": "jpg" } ### @@ -44,6 +44,27 @@ GET http://127.0.0.1:8000/generer/ Content-Type: application/json Accept: application/pdf +{ + "format": "linkedin", + "style": "missioncyber", + "linkcolor": "blue", + "tocdepth": 2, + "pdfengine": "lualatex", + "content": "# Comment améliorer ma sécurité informatique\n\n20 défis gratuits de 2 minutes chacun !", + "fontsize": 20, + "paperwidth": 1080, + "paperheight": 1080, + "margin": 180, + "extension": "jpg", + "vmargin": 300 +} + +### + +GET http://127.0.0.1:8000/generer/ +Content-Type: application/json +Accept: application/pdf + { "format": "slide169", "style": "jevalideca", @@ -55,5 +76,5 @@ Accept: application/pdf "paperwidth": 1920, "paperheight": 1080, "margin": 90, - "extension": "pdf" + "extension": "jpg" }