diff options
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: |
