feat: add image resizing option and update Open Graph image reference in edit template

main
Antonio De Lucreziis 6 months ago
parent df58f1f599
commit 825c18bcfe

@ -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(

@ -8,7 +8,7 @@
<meta property="og:description" content="View and edit the LaTeX/TikZ code for diagram {{ run_id }}." />
<meta property="og:type" content="website" />
<meta property="og:url" content="{{ base_path }}/d/{{ run_id }}" />
<meta property="og:image" content="{{ base_path }}/d/{{ run_id }}/files/diagram.png" />
<meta property="og:image" content="{{ base_path }}/d/{{ run_id }}/files/preview.png" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link

Loading…
Cancel
Save