Use DM-Logo_compress.png directly for email logo, remove Pillow resize logic
This commit is contained in:
parent
0698c84026
commit
60909c7122
4 changed files with 13 additions and 33 deletions
40
app.py
40
app.py
|
|
@ -298,47 +298,25 @@ def send_email(to, subject, body, attachments=None, inline_images=None):
|
||||||
server.login(cfg['SMTP_USER'], cfg['SMTP_PASS'])
|
server.login(cfg['SMTP_USER'], cfg['SMTP_PASS'])
|
||||||
server.send_message(msg)
|
server.send_message(msg)
|
||||||
|
|
||||||
|
|
||||||
def build_signature_images():
|
def build_signature_images():
|
||||||
"""
|
"""Return inline image tuple list for the Dionysis Media logo if present."""
|
||||||
Return inline image tuple list for the Dionysis Media logo if present.
|
|
||||||
The logo path is configurable via /admin/settings. A downscaled, compressed
|
|
||||||
email-sized JPEG copy is generated in the upload folder so attachments stay small.
|
|
||||||
:return: list of (path, cid) tuples. Empty if no logo is configured or not found.
|
|
||||||
"""
|
|
||||||
cfg = load_booth_settings()
|
cfg = load_booth_settings()
|
||||||
logo_path = cfg.get('logo_path') or '/mnt/Storage/DM-Logo.png'
|
logo_path = cfg.get('logo_path') or '/mnt/Storage/DM-Logo_compress.png'
|
||||||
logo_file = Path(logo_path)
|
logo_file = Path(logo_path)
|
||||||
if not logo_file.exists():
|
if not logo_file.exists():
|
||||||
return []
|
return []
|
||||||
# Cache a small email-friendly JPEG inside the upload folder.
|
return [(str(logo_file), 'dm-logo')]
|
||||||
cache_dir = Path(current_app.config['UPLOAD_FOLDER'])
|
|
||||||
cache_dir.mkdir(parents=True, exist_ok=True)
|
|
||||||
email_logo = cache_dir / 'dm-logo.email.jpg'
|
|
||||||
try:
|
|
||||||
from PIL import Image
|
|
||||||
with Image.open(logo_file) as im:
|
|
||||||
im.thumbnail((600, 600))
|
|
||||||
if im.mode in ('RGBA', 'LA', 'P'):
|
|
||||||
# Composite transparent images onto a white background for JPEG.
|
|
||||||
background = Image.new('RGB', im.size, (255, 255, 255))
|
|
||||||
if im.mode == 'P':
|
|
||||||
im = im.convert('RGBA')
|
|
||||||
background.paste(im, mask=im.split()[-1] if im.mode == 'RGBA' else None)
|
|
||||||
im = background
|
|
||||||
else:
|
|
||||||
im = im.convert('RGB')
|
|
||||||
im.save(email_logo, format='JPEG', optimize=True, quality=85)
|
|
||||||
except Exception:
|
|
||||||
# If resize fails, fall back to the original file.
|
|
||||||
return [(str(logo_file), 'dm-logo')]
|
|
||||||
return [(str(email_logo), 'dm-logo')]
|
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Public customer routes
|
# Public customer routes
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@app.route('/')
|
||||||
|
def index():
|
||||||
|
"""Root route: redirect customers straight to the request form."""
|
||||||
|
return redirect(url_for('request_form'))
|
||||||
|
|
||||||
|
|
||||||
@app.route('/request', methods=['GET', 'POST'])
|
@app.route('/request', methods=['GET', 'POST'])
|
||||||
@limiter.limit("5 per minute")
|
@limiter.limit("5 per minute")
|
||||||
|
|
@ -712,7 +690,7 @@ def admin_settings():
|
||||||
'smtp_user': runtime_settings.get('smtp_user', current_app.config['SMTP_USER']),
|
'smtp_user': runtime_settings.get('smtp_user', current_app.config['SMTP_USER']),
|
||||||
'smtp_from': runtime_settings.get('smtp_from', current_app.config['SMTP_FROM']),
|
'smtp_from': runtime_settings.get('smtp_from', current_app.config['SMTP_FROM']),
|
||||||
'smtp_pass_set': bool(runtime_settings.get('smtp_pass', '')),
|
'smtp_pass_set': bool(runtime_settings.get('smtp_pass', '')),
|
||||||
'logo_path': runtime_settings.get('logo_path', '/mnt/Storage/DM-Logo.png'),
|
'logo_path': runtime_settings.get('logo_path', '/mnt/Storage/DM-Logo_compress.png'),
|
||||||
}
|
}
|
||||||
|
|
||||||
# Compute upload folder stats.
|
# Compute upload folder stats.
|
||||||
|
|
|
||||||
3
booth_settings.json
Normal file
3
booth_settings.json
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"logo_path": "/mnt/Storage/DM-Logo_compress.png"
|
||||||
|
}
|
||||||
|
|
@ -15,4 +15,3 @@ werkzeug
|
||||||
mutagen
|
mutagen
|
||||||
flask-limiter
|
flask-limiter
|
||||||
cryptography
|
cryptography
|
||||||
Pillow
|
|
||||||
|
|
|
||||||
|
|
@ -265,7 +265,7 @@
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Logo Path</td>
|
<td>Logo Path</td>
|
||||||
<td><input type="text" id="logo_path" name="logo_path" value="{{ email_form.logo_path }}" placeholder="e.g. /mnt/Storage/DM-Logo.png"></td>
|
<td><input type="text" id="logo_path" name="logo_path" value="{{ email_form.logo_path }}" placeholder="e.g. /mnt/Storage/DM-Logo_compress.png"></td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<button type="submit">Save Email Settings</button>
|
<button type="submit">Save Email Settings</button>
|
||||||
|
|
|
||||||
Reference in a new issue