Skip to content

Instantly share code, notes, and snippets.

@kampelmuehler
Created July 27, 2021 06:39
Show Gist options
  • Select an option

  • Save kampelmuehler/0a3381a29b17c7766e8924434c4ea999 to your computer and use it in GitHub Desktop.

Select an option

Save kampelmuehler/0a3381a29b17c7766e8924434c4ea999 to your computer and use it in GitHub Desktop.

Revisions

  1. kampelmuehler created this gist Jul 27, 2021.
    28 changes: 28 additions & 0 deletions mirror_tile_and_crop.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    from PIL import Image
    from PIL.ImageOps import flip, mirror
    import numpy as np

    iseven = lambda x: (x % 2) == 0


    def mirror_tile_crop(img: Image.Image, target_height=8192, target_width=8192) -> Image.Image:
    width, height = img.size

    width_repeat = int(np.ceil(target_width / width))
    height_repeat = int(np.ceil(target_height / height))

    out_image = Image.new('RGB', (width_repeat * width, height_repeat * height))

    for i in range(width_repeat):
    for j in range(height_repeat):
    temp_img = img.copy()
    if iseven(i):
    temp_img = mirror(temp_img)
    if iseven(j):
    temp_img = flip(temp_img)
    out_image.paste(temp_img, (i * width, j * height))

    return out_image.crop((0, 0, target_width, target_height))


    mirror_tile_crop(Image.open('test.jpg')).save('test_tiled.jpg')