(img)
| 125 | existing.add(fname) |
| 126 | |
| 127 | def crop_image(img): |
| 128 | w, h = img.size |
| 129 | if h == w: |
| 130 | return img |
| 131 | normal = min(h, w) |
| 132 | diff_w = w - normal |
| 133 | diff_h = h - normal |
| 134 | crop_top = diff_h // 2 |
| 135 | crop_bot = diff_h // 2 + diff_h % 2 |
| 136 | crop_left = diff_w // 2 |
| 137 | crop_right = diff_w // 2 + diff_w % 2 |
| 138 | box = (crop_left, crop_top, w - crop_right, h - crop_bot) |
| 139 | return img.crop(box) |
| 140 | |
| 141 | |
| 142 | def get_icon_file(res_path, size): |