Created
March 11, 2015 20:23
-
-
Save objarni/78c455b41bf4f9ed398b to your computer and use it in GitHub Desktop.
Skära upp Eins bild i bitar
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 Image | |
block = 7 | |
img = Image.open('cutup.png') | |
w, h = img.size | |
print 'Image (w,h)=(%d,%d)' % (w,h) | |
ws, hs = w/float(block), h/float(block) | |
print 'Sub image (w,h)=(%d,%d)' % (ws, hs) | |
for i in range(0, block): | |
for j in range(0, block): | |
filename = 'try3/cut_%d_%d.png' % (i, j) | |
left = i * ws | |
upper = j * hs | |
right = left + ws - 1 | |
lower = upper + hs - 1 | |
print 'Saving subimage %s (x1,y1,x2,y2)=(%d,%d,%d,%d).' % (filename, left, upper, right, lower) | |
bbox = tuple(map(int, (left, upper, right, lower))) | |
img.crop( bbox ).save(filename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment