From 3dea56058012cefd7f2f2fe8772dd9d19c4e1c85 Mon Sep 17 00:00:00 2001 From: CODING-DARSH Date: Sat, 6 Jun 2026 20:59:35 +0530 Subject: [PATCH] fix: correct resize dimension order for non-square images --- fastembed/image/transform/functional.py | 3 ++- tests/test_image_onnx_embeddings.py | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/fastembed/image/transform/functional.py b/fastembed/image/transform/functional.py index 9d9e2197e..0f17b14bb 100644 --- a/fastembed/image/transform/functional.py +++ b/fastembed/image/transform/functional.py @@ -98,7 +98,8 @@ def resize( resample: int | Image.Resampling = Image.Resampling.BILINEAR, ) -> Image.Image: if isinstance(size, tuple): - return image.resize(size, resample) + height, width = size + return image.resize((width, height), resample) height, width = image.height, image.width short, long = (width, height) if width <= height else (height, width) diff --git a/tests/test_image_onnx_embeddings.py b/tests/test_image_onnx_embeddings.py index 5ac5e44f1..56295926a 100644 --- a/tests/test_image_onnx_embeddings.py +++ b/tests/test_image_onnx_embeddings.py @@ -173,3 +173,24 @@ def test_session_options(model_cache, model_name) -> None: model = ImageEmbedding(model_name=model_name, enable_cpu_mem_arena=False) session_options = model.model.model.get_session_options() assert session_options.enable_cpu_mem_arena is False + +def test_resize_dimension_order(): + from PIL import Image + from fastembed.image.transform.operators import Resize + + # Define target dimensions: Height=100, Width=200 + # FastEmbed's Resize transform semantically expects (height, width) + target_height, target_width = 100, 200 + resizer = Resize(size=(target_height, target_width)) + + # Create a square 50x50 dummy image + img = Image.new("RGB", (50, 50)) + + # Apply Resize transform (expects list, returns list) + resized_img = resizer([img])[0] + + # PIL's image.size property returns (width, height) + # Buggy: produces (100, 200) -> width=100, height=200 + # Correct: should produce (200, 100) -> width=200, height=100 + assert resized_img.size == (target_width, target_height), \ + f"Expected size (W={target_width}, H={target_height}), but got {resized_img.size}"