Add image loading and validation features with unit tests#25
Add image loading and validation features with unit tests#25not-lain merged 10 commits intonot-lain:mainfrom
Conversation
not-lain
left a comment
There was a problem hiding this comment.
Awesome work @BouajilaHamza , thanks a lot for your contribution, I left some comments and suggestions, could you attend to them
src/loadimg/utils.py
Outdated
| else: | ||
| raise ValueError(f"Unsupported output type: {output_type}") | ||
| # List of sources | ||
| image_paths = imgs |
There was a problem hiding this comment.
we could have looped over imgs directly instead of creating an extra parameter, mean in this case we case image_paths could be a list of pillow images so it's not technically paths per say
There was a problem hiding this comment.
Hmm i got that.
Insightful !
| def validate_image(img: Image.Image) -> tuple[bool, str]: | ||
| """Validates an image for basic requirements. | ||
|
|
||
| Args: | ||
| img: PIL Image to validate | ||
|
|
||
| Returns: | ||
| tuple[bool, str]: (is_valid, error_message) | ||
| """ | ||
| if not isinstance(img, Image.Image): | ||
| return False, "Input is not a PIL Image" | ||
|
|
||
| if img.size[0] * img.size[1] == 0: | ||
| return False, "Image has zero dimensions" | ||
|
|
||
| try: | ||
| img.verify() | ||
| return True, "" | ||
| except Exception as e: | ||
| return False, f"Image verification failed: {str(e)}" |
There was a problem hiding this comment.
could you add a test for this or an example, I haven't really encountered similar errors with loadimg before
There was a problem hiding this comment.
Okey i will check that
There was a problem hiding this comment.
@not-lain I have added simple testing function in loadimg file, you can check it
Co-authored-by: Hafedh Hichri <70411813+not-lain@users.noreply.github.com>
Co-authored-by: Hafedh Hichri <70411813+not-lain@users.noreply.github.com>
not-lain
left a comment
There was a problem hiding this comment.
LGTM, thanks a lot @BouajilaHamza ✨
| # Create an image with zero width to simulate zero dimensions | ||
| img = Image.new("RGB", (0, 10)) |
There was a problem hiding this comment.
I see why we need the verification now, thanks for iterating
|
LGTM, merging |
Uh oh!
There was an error while loading. Please reload this page.