diff options
| author | jules@lens <julescarbon@gmail.com> | 2019-01-09 17:51:55 +0100 |
|---|---|---|
| committer | jules@lens <julescarbon@gmail.com> | 2019-01-09 17:51:55 +0100 |
| commit | 08d9cb4994d1580d5f79a84534a1d01f3e14a531 (patch) | |
| tree | 5a59bdaec8238a177c503b8b1478722bbb3c9e3c | |
| parent | 8a38ca53d6e8303d73e78c6eb59da7d1c59772c5 (diff) | |
fix math
| -rw-r--r-- | crop-thirds.py | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/crop-thirds.py b/crop-thirds.py index 657062d..d9172b9 100644 --- a/crop-thirds.py +++ b/crop-thirds.py @@ -20,7 +20,7 @@ parser.add_argument('--vertical_offset', type=int, default=256) # parser.add_argument('--dst_height', type=int, default=512) parser.add_argument('--count', type=int, default=3) parser.add_argument('--max', type=int, default=99997) -parser.add_argument('--crop_aspect' type=float, default=1.5) +parser.add_argument('--crop_aspect', type=float, default=1.5) parser.add_argument('--aspect', type=float, default=3.0) # parser.add_argument('--folder_id', type=int, required=True) parser.add_argument('--margin', type=int, default=16) @@ -36,9 +36,12 @@ dst_height = int(dst_width / opt.aspect) crop_width = dst_width crop_height = int(dst_width / opt.aspect * opt.crop_aspect) +x_margin = opt.margin +y_margin = opt.margin * opt.crop_aspect + crop_size = (crop_width, crop_height,) -dst_size = (dst_width, dst_height,) -y0 = opt.vertical_offset - crop_height / 2 - margin +dst_size = (dst_width + opt.margin * 2, dst_height + opt.margin * 2,) +y0 = opt.vertical_offset - crop_height / 2 - y_margin crops = [] paths = [] @@ -49,10 +52,10 @@ if not opt.no_clobber: rmtree(out_path) for i in range(opt.count): - x = int(i / opt.count * dst_width) - margin + x = int(i / opt.count * dst_width) - x_margin if x < 0: x += dst_width - crops.append((x, y0, x + crop_width + margin + margin, y0 + crop_height + margin + margin,)) + crops.append((x, y0, x + crop_width + x_margin + x_margin, y0 + crop_height + y_margin + y_margin,)) path = os.path.join(out_path, chr(97 + i)) os.makedirs(path) paths.append(path) @@ -72,7 +75,7 @@ def build_thumbnail(i, fn): if (i % 100) == 0: print("{}...".format(i)) - canvas = Image.new('RGB', (int(src_width + dst_width + margin), src_height,)) + canvas = Image.new('RGB', (int(src_width + dst_width + x_margin), src_height,)) image = Image.open(fn) canvas.paste(image, (0, 0)) canvas.paste(image, (src_width, 0)) |
