Last active
January 8, 2022 17:30
-
-
Save fopina/6e97829e33de8a8c72c2d1bf65ed5ab9 to your computer and use it in GitHub Desktop.
Poor Man's Lenticular
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# https://www.youtube.com/watch?v=mmGB9ADKr5Y | |
import argparse | |
from PIL import Image | |
DEFAULT_STRIPS = 8 | |
def build_parser(): | |
parser = argparse.ArgumentParser(description='Slice 2 images and put them back together.') | |
parser.add_argument('images', metavar='FILE', type=str, nargs=2, | |
help='image file') | |
parser.add_argument('--strips', type=int, default=DEFAULT_STRIPS, | |
help='number of strips (default: %d)' % DEFAULT_STRIPS) | |
return parser | |
def main(args): | |
im1 = Image.open(args.images[0]) | |
im2 = Image.open(args.images[1]) | |
stl = im1.size[0] / args.strips | |
im1_strips = [] | |
im2_strips = [] | |
for s in xrange(args.strips): | |
im1_strips.append(im1.crop((s * stl, 0, (s + 1) * stl, im1.size[1]))) | |
im2_strips.append(im2.crop((s * stl, 0, (s + 1) * stl, im1.size[1]))) | |
new_im = Image.new('RGB', (stl * args.strips * 2, im1.size[1])) | |
for s in xrange(args.strips): | |
new_im.paste(im1_strips[s], (s * 2 * stl, 0)) | |
new_im.paste(im2_strips[s], ((s * 2 + 1) * stl, 0)) | |
new_im.show() | |
if __name__ == '__main__': | |
main(build_parser().parse_args()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment