Created
July 27, 2021 06:39
-
-
Save kampelmuehler/0a3381a29b17c7766e8924434c4ea999 to your computer and use it in GitHub Desktop.
Tiles an image and mirrors every other tile to make seamless transitions
This file contains hidden or 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
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') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment