Add an opt-in to skip Instagram's exact resolution requirement
Some users want the assembled HDR JPEG for somewhere other than Instagram, where the exact 1080x1080/1080x1350/1080x566 match isn't relevant. A checkbox on the form now lets the whole batch skip that specific check. The SDR/HDR dimension-match check still always applies, since that's a technical requirement for the gain map to align, not an Instagram-specific rule.
This commit is contained in:
+5
-3
@@ -8,7 +8,7 @@ from flask import abort, redirect, render_template, request, send_file, url_for
|
||||
from . import assembler, jobs, validation
|
||||
|
||||
|
||||
def _process_pair(job_dir, index, sdr_file, hdr_file):
|
||||
def _process_pair(job_dir, index, sdr_file, hdr_file, ignore_ig_resolution=False):
|
||||
"""Runs one SDR/HDR pair through validation + assembly. Returns an item
|
||||
dict for the job report; never raises — failures are recorded in it."""
|
||||
name = hdr_file.filename or sdr_file.filename or f"pair {index}"
|
||||
@@ -28,7 +28,7 @@ def _process_pair(job_dir, index, sdr_file, hdr_file):
|
||||
sdr_file.save(sdr_path)
|
||||
hdr_file.save(hdr_path)
|
||||
|
||||
ig_error = validation.instagram_resolution_error(sdr_path, hdr_path)
|
||||
ig_error = validation.instagram_resolution_error(sdr_path, hdr_path, ignore_ig_resolution)
|
||||
if ig_error:
|
||||
for p in (sdr_path, hdr_path):
|
||||
p.unlink(missing_ok=True)
|
||||
@@ -62,11 +62,13 @@ def register_routes(app):
|
||||
if len(sdr_files) != len(hdr_files):
|
||||
return render_template("index.html", error="Each pair needs both an SDR and an HDR file."), 400
|
||||
|
||||
ignore_ig_resolution = request.form.get("ignore_ig_resolution") == "on"
|
||||
|
||||
job_id = uuid.uuid4().hex[:12]
|
||||
job_dir = jobs.new_job_dir(job_id)
|
||||
|
||||
items = [
|
||||
_process_pair(job_dir, i, sdr_file, hdr_file)
|
||||
_process_pair(job_dir, i, sdr_file, hdr_file, ignore_ig_resolution)
|
||||
for i, (sdr_file, hdr_file) in enumerate(zip(sdr_files, hdr_files), start=1)
|
||||
]
|
||||
|
||||
|
||||
+11
-3
@@ -42,9 +42,17 @@ def probe_dimensions(path: Path) -> tuple[int, int]:
|
||||
raise ValueError(f"could not read image dimensions ({e})") from e
|
||||
|
||||
|
||||
def instagram_resolution_error(sdr_path: Path, hdr_path: Path) -> str | None:
|
||||
def instagram_resolution_error(
|
||||
sdr_path: Path, hdr_path: Path, ignore_ig_resolution: bool = False,
|
||||
) -> str | None:
|
||||
"""Returns an error message if the pair doesn't meet Instagram's feed
|
||||
requirements, otherwise None."""
|
||||
requirements, otherwise None.
|
||||
|
||||
The dimension-match check always applies: mismatched SDR/HDR
|
||||
dimensions misalign the gain map regardless of what platform the
|
||||
result is for. ignore_ig_resolution skips only the exact-match check
|
||||
against Instagram's own feed resolutions, for results meant for
|
||||
somewhere other than Instagram."""
|
||||
try:
|
||||
sdr_w, sdr_h = probe_dimensions(sdr_path)
|
||||
hdr_w, hdr_h = probe_dimensions(hdr_path)
|
||||
@@ -57,7 +65,7 @@ def instagram_resolution_error(sdr_path: Path, hdr_path: Path) -> str | None:
|
||||
"dimensions, otherwise the gain map will misalign."
|
||||
)
|
||||
|
||||
if (sdr_w, sdr_h) not in IG_RESOLUTIONS:
|
||||
if not ignore_ig_resolution and (sdr_w, sdr_h) not in IG_RESOLUTIONS:
|
||||
allowed = ", ".join(f"{w}x{h} ({label})" for (w, h), label in IG_RESOLUTIONS.items())
|
||||
return f"Image is {sdr_w}x{sdr_h} — Instagram requires an exact match to one of: {allowed}."
|
||||
|
||||
|
||||
Reference in New Issue
Block a user