Created
January 28, 2012 13:19
-
-
Save mgedmin/1694281 to your computer and use it in GitHub Desktop.
Hacky tool to slice a large image into tiles
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
import sys | |
from PIL import Image | |
tile_size = (1024, 1024) | |
def main(): | |
img = Image.open(sys.argv[1]) | |
tile_w, tile_h = tile_size | |
img_w, img_h = img.size | |
for row, y in enumerate(range(0, img_h, tile_h)): | |
for col, x in enumerate(range(0, img_w, tile_w)): | |
filename = 'tile-%03d-%03d.png' % (row, col) | |
w = min(tile_w, img_w - x) | |
h = min(tile_h, img_h - y) | |
img.crop((x, y, x+w, y+h)).save(filename) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment