Created
April 26, 2012 21:59
-
-
Save zeraien/2503530 to your computer and use it in GitHub Desktop.
Python script that will convert a given 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 Image | |
import sys | |
image = Image.open(sys.argv[1]) | |
tile_width = int(sys.argv[2]) | |
tile_height = int(sys.argv[3]) | |
zoom_level = sys.argv[4] | |
if image.size[0] % tile_width == 0 and image.size[1] % tile_height ==0 : | |
currentx = 0 | |
currenty = 0 | |
while currenty < image.size[1]: | |
while currentx < image.size[0]: | |
print currentx,",",currenty | |
tile = image.crop((currentx,currenty,currentx + tile_width,currenty + tile_height)) | |
tile.save("x" + str(currentx) + "y" + str(currenty) + "z" + zoom_level + ".png","PNG") | |
currentx += tile_width | |
currenty += tile_height | |
currentx = 0 | |
else: | |
print "sorry your image does not fit neatly into",tile_width,"*",tile_height,"tiles" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment