MCPcopy Create free account
hub / github.com/agentforce314/clawcodex / _resize_to_envelope

Function _resize_to_envelope

src/utils/image_processor.py:221–235  ·  view source on GitHub ↗

Resize ``img`` to fit within ``max_w × max_h`` preserving aspect ratio. Returns ``(resized_img, new_w, new_h)``. No-op when image already fits. Matches sharp's ``fit: 'inside', withoutEnlargement: true``.

(img: Any, max_w: int, max_h: int)

Source from the content-addressed store, hash-verified

219
220
221def _resize_to_envelope(img: Any, max_w: int, max_h: int) -> tuple[Any, int, int]:
222 """Resize ``img`` to fit within ``max_w × max_h`` preserving aspect ratio.
223
224 Returns ``(resized_img, new_w, new_h)``. No-op when image already fits.
225 Matches sharp's ``fit: 'inside', withoutEnlargement: true``.
226 """
227 Image, _ = _pil()
228 w, h = img.size
229 if w <= max_w and h <= max_h:
230 return img, w, h
231 scale = min(max_w / w, max_h / h)
232 new_w = max(1, int(w * scale))
233 new_h = max(1, int(h * scale))
234 resized = img.resize((new_w, new_h), Image.LANCZOS)
235 return resized, new_w, new_h
236
237
238# ---------------------------------------------------------------------------

Callers 2

maybe_resize_imageFunction · 0.85

Calls 1

_pilFunction · 0.85

Tested by

no test coverage detected