Skip to content
Snippets Groups Projects

Fix resizing

Merged Yoann Schneider requested to merge fix-resize into main
2 files
+ 33
13
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -6,7 +6,6 @@ import pickle
import random
from collections import defaultdict
from concurrent.futures import Future, ThreadPoolExecutor
from functools import cached_property
from pathlib import Path
from typing import Dict, List, Optional, Union
from uuid import UUID
@@ -91,23 +90,26 @@ class ArkindexExtractor:
# Image download tasks to process
self.tasks: List[Dict[str, str]] = []
@cached_property
def max_resize(self):
# We keep the aspect ratio so we only use on dimension, the biggest one
if self.max_width > self.max_height:
return f"{self.max_width},"
return f",{self.max_height}"
def get_iiif_size_arg(self, width: int, height: int) -> str:
if (self.max_width is None or width <= self.max_width) and (
self.max_height is None or height <= self.max_height
):
return IIIF_FULL_SIZE
# Resizing if the image is bigger than the wanted size.
if self.max_width and self.max_height:
return self.max_resize
return f"{self.max_width or ''},{self.max_height or ''}"
bigger_width = self.max_width and width >= self.max_width
bigger_height = self.max_height and height >= self.max_height
if bigger_width and bigger_height:
# Resize to the biggest dim to keep aspect ratio
# Only resize width is bigger than max size
# This ratio tells which dim needs the biggest shrinking
ratio = width * self.max_height / (height * self.max_width)
return f"{self.max_width}," if ratio > 1 else f",{self.max_height}"
elif bigger_width:
return f"{self.max_width},"
# Only resize height is bigger than max size
elif bigger_height:
return f",{self.max_height}"
def build_iiif_url(self, polygon, image_url):
bbox = polygon_to_bbox(json.loads(str(polygon)))
Loading