diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2019-01-09 16:33:16 +0100 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2019-01-09 16:33:16 +0100 |
| commit | be592bc9662679f40ac2c426a69aa9d204deafd9 (patch) | |
| tree | 4932fe2efe78fd66ca7efbb92b21262bf968f7a5 /crop-thirds.py | |
| parent | b711d38f14c6ccb423f9767cf922735de07e57f4 (diff) | |
crop thirds with resize
Diffstat (limited to 'crop-thirds.py')
| -rw-r--r-- | crop-thirds.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/crop-thirds.py b/crop-thirds.py index e2809a2..900f6f4 100644 --- a/crop-thirds.py +++ b/crop-thirds.py @@ -20,6 +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('--aspect', type=float, default=3.0) # parser.add_argument('--folder_id', type=int, required=True) parser.add_argument('--margin', type=int, default=16) @@ -31,6 +32,11 @@ src_height = 512 dst_width = int(src_width / opt.count) dst_height = int(dst_width / opt.aspect) + +crop_width = dst_width +crop_height = int(dst_width / opt.aspect * crop_aspect) + +crop_size = (crop_width, crop_height,) dst_size = (dst_width, dst_height,) y0 = opt.vertical_offset - dst_height / 2 - margin @@ -46,7 +52,7 @@ for i in range(opt.count): x = int(i / opt.count * dst_width) - margin if x < 0: x += dst_width - crops.append((x, y0, x + dst_width + margin + margin, y0 + dst_height + margin + margin,)) + crops.append((x, y0, x + crop_width + margin + margin, y0 + crop_height + margin + margin,)) path = os.path.join(out_path, chr(97 + i)) os.makedirs(path) paths.append(path) @@ -72,7 +78,7 @@ def build_thumbnail(i, fn): canvas.paste(image, (src_width, 0)) for n, path in enumerate(paths): - image.crop(crops[n]).save(os.path.join(path, out_fn)) + image.crop(crops[n]).resize(dst_size).save(os.path.join(path, out_fn)) chunksize = 3 with Pool(processes=cpu_count()) as pool: |
