diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2019-01-09 18:26:10 +0100 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2019-01-09 18:26:10 +0100 |
| commit | 93afd8beafa141f555da54233dd2de3d25109111 (patch) | |
| tree | 0fb53764368e4b24ba29f507ceba162c919f8ba9 /crop-thirds.py | |
| parent | 6d1c7b2101a09451d091e4e3229a1c8a324dc9b1 (diff) | |
gotta crop
Diffstat (limited to 'crop-thirds.py')
| -rw-r--r-- | crop-thirds.py | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/crop-thirds.py b/crop-thirds.py index ea6ba55..d8fc0b4 100644 --- a/crop-thirds.py +++ b/crop-thirds.py @@ -50,9 +50,13 @@ if not opt.no_clobber: for i in range(opt.count): x = int(i / opt.count * dst_width) - margin + w = x + crop_width + margin + margin + if w > src_width: + w = src_width + x = src_width - (crop_width + margin + margin) if x < 0: x = 0 - crops.append((x, y0, x + crop_width + margin + margin, y0 + crop_height + margin + margin,)) + crops.append((x, y0, w, y0 + crop_height + margin + margin,)) path = os.path.join(out_path, chr(97 + i)) os.makedirs(path) paths.append(path) @@ -72,13 +76,11 @@ 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 + margin), src_height,)) image = Image.open(fn) - canvas.paste(image, (0, 0)) - canvas.paste(image, (src_width, 0)) for n, path in enumerate(paths): - canvas.crop(crops[n]).resize(dst_size).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: |
