From 825c18bcfef2e5de68ca7488a925b5671436a693 Mon Sep 17 00:00:00 2001 From: Antonio De Lucreziis Date: Sat, 27 Dec 2025 00:04:39 +0100 Subject: [PATCH] feat: add image resizing option and update Open Graph image reference in edit template --- main.py | 37 +++++++++++++++++++++++++++++++++++-- templates/edit.html | 2 +- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 8e3b2fa..8b33c0a 100644 --- a/main.py +++ b/main.py @@ -448,7 +448,12 @@ def _compile_pdflatex( def _render_png_with_magick( - run_dir: Path, pdf_path: Path, run_logger: RunLogger, section_title: str, png_name: str = "diagram.png" + run_dir: Path, + pdf_path: Path, + run_logger: RunLogger, + section_title: str, + png_name: str = "diagram.png", + size: str | None = None, ) -> Optional[Path]: png_path = run_dir / png_name @@ -464,8 +469,23 @@ def _render_png_with_magick( "remove", "-alpha", "off", - str(png_path), ] + + # If size is specified, add center-fit resizing (e.g., "1200x630") + if size: + cmd.extend( + [ + "-resize", + size, + "-gravity", + "center", + "-extent", + size, + ] + ) + + cmd.append(str(png_path)) + code, out = _run_cmd(cmd, cwd=run_dir, timeout_s=5, py_logger=run_logger.py) run_logger.section(section_title, out) if code == 0 and png_path.exists(): @@ -571,6 +591,19 @@ def _compile_phase( if pdf_path else None ) + # Render preview.png with OG image size (1200x630, center-fit) + preview_path = ( + _render_png_with_magick( + run_dir, + pdf_path, + run_log, + section_title=f"{phase}.magick.preview", + png_name="preview.png", + size="1200x630", + ) + if pdf_path + else None + ) elapsed_ms = int((time.monotonic() - started) * 1000) _save_compile_state( diff --git a/templates/edit.html b/templates/edit.html index 040b573..420f052 100644 --- a/templates/edit.html +++ b/templates/edit.html @@ -8,7 +8,7 @@ - +