Last active
April 22, 2018 05:30
-
-
Save zaftzaft/3ed1a40c26224258801511b622dd6b9c to your computer and use it in GitHub Desktop.
画像を分割するやつ
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
import sys | |
from PIL import Image | |
im = Image.open(sys.argv[1]) | |
(w, h) = im.size | |
im.crop((0, 0, w/2, h/2)).save("f/a.png") | |
im.crop((w/2, 0, w, h/2)).save("f/b.png") | |
im.crop((0, h/2, w/2, h)).save("f/c.png") | |
im.crop((w/2, h/2, w, h)).save("f/d.png") | |
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
import sys | |
from PIL import Image | |
im = Image.open(sys.argv[1]) | |
(w, h) = im.size | |
wn = 3 | |
hn = 3 | |
p = 10 | |
canvas = Image.new("RGB", (w+(p*(wn-1)), h+(p*(hn-1))), (0,0,0)) | |
for y in range(0, hn): | |
for x in range(0, wn): | |
x1 = x * (w/wn) | |
x2 = (x+1) * (w/wn) | |
y1 = y * (h/hn) | |
y2 = (y+1) * (h/hn) | |
fragm = im.crop((x1, y1, x2, y2)) | |
fragm.save("f/{}-{}.png".format(x, y)) | |
canvas.paste(fragm, (int(x1+(p*x)), int(y1+(p*y)))) | |
canvas.save("f/t.png") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment