Skip to content

Commit 348ea3c

Browse files
committed
get height from server instead of calculating it on the client
1 parent 142a52a commit 348ea3c

2 files changed

Lines changed: 16 additions & 16 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# vim
2+
*.swp
3+
14
# Byte-compiled / optimized / DLL files
25
__pycache__/
36
*.py[cod]

src/bma_client.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def get_job_assignment(self, file_uuid: uuid.UUID | None = None) -> list[dict[st
122122
r = self.client.post(url, data=json.dumps(data)).raise_for_status()
123123
response = r.json()["bma_response"]
124124
except httpx.HTTPStatusError as e:
125-
if e.response.status_code == HTTPStatus.NotFound:
125+
if e.response.status_code == HTTPStatus.NOT_FOUND:
126126
response = []
127127
else:
128128
raise
@@ -194,30 +194,27 @@ def handle_image_conversion_job(self, job: dict[str, str], orig: Path) -> tuple[
194194
logger.debug("Rotating image (if needed)...")
195195
start = time.time()
196196
image = ImageOps.exif_transpose(image) # creates a copy with rotation normalised
197-
logger.debug(f"Rotating image took {time.time() - start} seconds, image is now {image.size}")
197+
orig_ar = Fraction(*image.size)
198+
logger.debug(f"Rotating image took {time.time() - start} seconds, image is now {image.size} original AR is {orig_ar}")
198199

199200
logger.debug("Getting exif metadata from image...")
200201
start = time.time()
201202
exif = image.getexif()
202203
logger.debug(f"Getting exif data took {time.time() - start} seconds")
203204

204-
logger.debug("Calculating size and ratio...")
205-
start = time.time()
206-
if job["aspect_ratio_numerator"] and job["aspect_ratio_denominator"]:
207-
# height is calculated based on requested width and AR
208-
ratio = Fraction(job["aspect_ratio_numerator"], job["aspect_ratio_denominator"])
209-
height = math.floor(job["width"] / ratio)
210-
else:
211-
# height is a fraction of width, keeping AR the same
212-
ratio = None
213-
height = math.floor(job["width"] / Fraction(*image.size))
214-
size = math.floor(job["width"]), math.floor(height)
215-
logger.debug(f"Calculating size and AR took {time.time() - start} seconds")
205+
size = job["width"], job["height"]
206+
ratio = Fraction(*size)
216207

217-
logger.debug(f"Desired image size is {size}, AR {ratio}, converting image...")
208+
if job['custom_aspect_ratio']:
209+
orig = "custom"
210+
else:
211+
orig = "original"
212+
if orig_ar != ratio:
213+
orig += "(ish)"
214+
logger.debug(f"Desired image size is {size}, aspect ratio: {ratio} ({orig}), converting image...")
218215
start = time.time()
219216
# custom AR or not?
220-
if ratio:
217+
if job['custom_aspect_ratio']:
221218
image = ImageOps.fit(image, size)
222219
else:
223220
image.thumbnail(size)

0 commit comments

Comments
 (0)