(img)
| 59 | |
| 60 | |
| 61 | def crop_image(img): |
| 62 | w, h = img.size |
| 63 | if h == w: |
| 64 | return img |
| 65 | normal = min(h, w) |
| 66 | diff_w = w - normal |
| 67 | diff_h = h - normal |
| 68 | crop_top = diff_h // 2 |
| 69 | crop_bot = diff_h // 2 + diff_h % 2 |
| 70 | crop_left = diff_w // 2 |
| 71 | crop_right = diff_w // 2 + diff_w % 2 |
| 72 | box = (crop_left, crop_top, w - crop_right, h - crop_bot) |
| 73 | return img.crop(box) |
| 74 | |
| 75 | |
| 76 | def get_render(type_id): |