From 93afd8beafa141f555da54233dd2de3d25109111 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Wed, 9 Jan 2019 18:26:10 +0100 Subject: gotta crop --- crop-thirds.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'crop-thirds.py') 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: -- cgit v1.2.3-70-g09d2