Resize so small size to short_size
(image: Image, short_size: int)
| 59 | |
| 60 | |
| 61 | def resize(image: Image, short_size: int) -> Image: |
| 62 | """ |
| 63 | Resize so small size to short_size |
| 64 | """ |
| 65 | width, height = image.size |
| 66 | short = min(width, height) |
| 67 | long = max(width, height) |
| 68 | if short == short_size: |
| 69 | return image |
| 70 | new_short = short_size |
| 71 | new_long = int(short_size * long / short) |
| 72 | new_size = (new_short, new_long) if width <= height else (new_long, new_short) |
| 73 | return image.resize(new_size) |
| 74 | |
| 75 | |
| 76 | def center_crop(image: Image, size: Tuple[int, int]) -> Image: |