Add margin around an image top, right, bottom, left are the margin widths, in pixels margin_color is what to use for the margins
(pil_img, top, right, bottom, left, margin_color)
| 46 | |
| 47 | |
| 48 | def add_margin(pil_img, top, right, bottom, left, margin_color): |
| 49 | """ |
| 50 | Add margin around an image |
| 51 | |
| 52 | top, right, bottom, left are the margin widths, in pixels |
| 53 | margin_color is what to use for the margins |
| 54 | """ |
| 55 | width, height = pil_img.size |
| 56 | new_width = width + right + left |
| 57 | new_height = height + top + bottom |
| 58 | result = Image.new(pil_img.mode, (new_width, new_height), margin_color) |
| 59 | result.paste(pil_img, (left, top)) |
| 60 | return result |
| 61 | |
| 62 | |
| 63 | def set_crop_size(crop_size): |