Files
conjurer/librarian_functions.py
T
Michal Tuszowski a64fb2da57 Restructure: promote working_copy to repo root
Make the stable 'working copy' bot the canonical code at the repository
root so the install/deploy scripts operate against it again.

- Move working_copy/* to root (bot entrypoint is bot.py)
- Restore root-level install/ops scripts from c4fa88e (deploy.sh,
  install_main_bot.sh, status_report.*, conjurer.service, etc.)
- Fix deploy.sh: copy bot.py (was thin_client.py) and add the
  conanjurer_* modules; bump command count
- Remove side-by-side variant dirs (backup_old_docker, prototype_one,
  prototype_musician_one, musician_old, working_copy) and docker cruft
- Keep components as subdirs: conjurer_librarian, conjurer_musician,
  spotify_dl, yt_dlp, fonts, utils, docs

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-28 23:50:55 +02:00

29 lines
877 B
Python

# pdf_render.py
import io
try:
import fitz # PyMuPDF
_HAS_PYMUPDF = True
except Exception:
_HAS_PYMUPDF = False
from pdf2image import convert_from_path
def pdf_page_to_image_bytes(path: str, page_index: int = 0, zoom: float = 2.0, fmt: str = "PNG") -> bytes:
"""
Zwraca bytes obrazka z jednej strony PDF:
- PyMuPDF (szybki) jeśli dostępny,
- inaczej pdf2image + poppler (wymaga 'pdftoppm').
page_index: 0-based
"""
if _HAS_PYMUPDF:
doc = fitz.open(path)
page = doc.load_page(page_index)
mat = fitz.Matrix(zoom, zoom)
pix = page.get_pixmap(matrix=mat, alpha=False)
return pix.tobytes(fmt.lower())
# fallback
images = convert_from_path(path, first_page=page_index+1, last_page=page_index+1, fmt=fmt)
bio = io.BytesIO()
images[0].save(bio, fmt)
return bio.getvalue()