Expand image to a square of size {size}. Optionally trims borders first.
(image, size, do_trim=False, bg="white")
| 28 | return image.crop(bbox) if (bbox:=diff.getbbox()) else image |
| 29 | |
| 30 | def expand(image, size, do_trim=False, bg="white"): |
| 31 | """Expand image to a square of size {size}. Optionally trims borders first.""" |
| 32 | image = trim(image, bg=bg) if do_trim else image |
| 33 | return ImageOps.pad(image, (size, size), color=bg, method=Image.Resampling.LANCZOS) |
| 34 | |
| 35 | # based on transformers/image_utils.py (added support for rgba images) |
| 36 | def load(image: Image.Image | str | bytes, bg="white", timeout=None): |
no test coverage detected