Created
August 22, 2019 11:52
-
-
Save seungwonpark/aed77db2ffaeff36beefdb5ec11566c5 to your computer and use it in GitHub Desktop.
JOI style random picture
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
# pdftoppm joi-style.pdf outputname -png -r 300 -scale-to 1024 | |
import random | |
from PIL import Image | |
img = Image.open('joi-style-1.png') | |
w, h = img.size | |
print(img.size) | |
grid = 16 | |
lw = w // grid | |
lh = h // grid | |
arr = [x for x in range(grid**2)] | |
random.shuffle(arr) | |
out = Image.new('RGB', size=(w, h)) | |
for row in range(grid): | |
for col in range(grid): | |
temp = arr[row*grid+col] | |
r, c = temp // grid, temp % grid | |
# out[row*lh:row*(lh+1), col*lw:col*(lw+1)] = \ | |
part = img.crop((c*lw, r*lh, (c+1)*lw, (r+1)*lh)) | |
out.paste(part, (col*lw, row*lh)) | |
out.save('out.png') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment