Spaces:
Sleeping
Sleeping
Hussien Haider commited on
Commit Β·
4a95521
1
Parent(s): 5393837
fix: move logo prep to import time to ensure it runs
Browse files
app/services/certificate_service.py
CHANGED
|
@@ -102,32 +102,28 @@ def _ar(text: str) -> str:
|
|
| 102 |
|
| 103 |
|
| 104 |
# --------------------------------------------------------------------------- #
|
| 105 |
-
# Logo preparation (convert ALPHA-LOGO.png RGBA β RGB JPEG,
|
| 106 |
# --------------------------------------------------------------------------- #
|
| 107 |
|
| 108 |
_LOGO_JPG_PATH: Optional[str] = None
|
| 109 |
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
pil.save(path, format="JPEG", quality=95)
|
| 128 |
-
_LOGO_JPG_PATH = path
|
| 129 |
-
except Exception:
|
| 130 |
-
_LOGO_JPG_PATH = ""
|
| 131 |
|
| 132 |
|
| 133 |
# --------------------------------------------------------------------------- #
|
|
@@ -287,7 +283,6 @@ def build_certificate_pdf(
|
|
| 287 |
c.rect(0, H - i * 8*mm, BAR, 8*mm, fill=1, stroke=0)
|
| 288 |
|
| 289 |
# ββ Logo: ALPHA-LOGO.png ββ
|
| 290 |
-
_prepare_logo()
|
| 291 |
if _LOGO_JPG_PATH and os.path.exists(_LOGO_JPG_PATH):
|
| 292 |
logo_size = 20 * mm
|
| 293 |
logo_y = H - 34 * mm
|
|
|
|
| 102 |
|
| 103 |
|
| 104 |
# --------------------------------------------------------------------------- #
|
| 105 |
+
# Logo preparation (convert ALPHA-LOGO.png RGBA β RGB JPEG, at import time) #
|
| 106 |
# --------------------------------------------------------------------------- #
|
| 107 |
|
| 108 |
_LOGO_JPG_PATH: Optional[str] = None
|
| 109 |
|
| 110 |
+
try:
|
| 111 |
+
from PIL import Image as _PIL
|
| 112 |
+
from app.services.logo_data import LOGO_B64
|
| 113 |
+
_raw = base64.b64decode(LOGO_B64)
|
| 114 |
+
_pil = _PIL.open(io.BytesIO(_raw))
|
| 115 |
+
if _pil.mode != "RGB":
|
| 116 |
+
_bg = _PIL.new("RGB", _pil.size, (15, 27, 45))
|
| 117 |
+
if _pil.mode == "RGBA":
|
| 118 |
+
_bg.paste(_pil, mask=_pil.split()[3])
|
| 119 |
+
else:
|
| 120 |
+
_bg.paste(_pil)
|
| 121 |
+
_pil = _bg
|
| 122 |
+
_path = os.path.join(tempfile.gettempdir(), "ca_alpha_logo.jpg")
|
| 123 |
+
_pil.save(_path, format="JPEG", quality=95)
|
| 124 |
+
_LOGO_JPG_PATH = _path
|
| 125 |
+
except Exception:
|
| 126 |
+
_LOGO_JPG_PATH = ""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
|
| 128 |
|
| 129 |
# --------------------------------------------------------------------------- #
|
|
|
|
| 283 |
c.rect(0, H - i * 8*mm, BAR, 8*mm, fill=1, stroke=0)
|
| 284 |
|
| 285 |
# ββ Logo: ALPHA-LOGO.png ββ
|
|
|
|
| 286 |
if _LOGO_JPG_PATH and os.path.exists(_LOGO_JPG_PATH):
|
| 287 |
logo_size = 20 * mm
|
| 288 |
logo_y = H - 34 * mm
|