Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- from Tkinter import Tk
- import math
- import os
- from tkFileDialog import askopenfilename
- from PIL import Image
- Tk().withdraw() # we don't want a full GUI, so keep the root window from appearing
- filepath = askopenfilename() # show an "Open" dialog box and return the path to the selected file
- im = Image.open(filepath)
- print im.size
- Width = im.size[0]
- Height = im.size[1]
- Columns = int(math.ceil(im.size[0]/256)) + 1
- Rows = int(math.ceil(im.size[1]/256)) + 1
- print str(Columns) + " columns and " + str(Rows) + " rows."
- filefolder = filepath.split("/")
- filefolder.pop(len(filefolder) - 1)
- filefolder = "/".join(filefolder)
- filename = filepath.split("/")[len(filepath.split("/")) - 1]
- print(filepath)
- print filefolder
- print filename
- Before = time.time()
- os.system("convert -crop 256x256 \"" + filepath + '" "' + filefolder + '/tile_%d.tga"')
- print time.time() - Before
- RNS = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
- CNS = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p"]
- N = 0
- R = 0
- while R < Rows:
- C = 0
- while C < Columns:
- os.rename(filefolder + "/tile_" + str(N) + ".tga", filefolder + "/" + str(Width) + "_" + str(RNS[R]) + "_" + CNS[C] + "_loading.tga")
- N = N + 1
- C = C + 1
- R = R + 1
Advertisement
Add Comment
Please, Sign In to add comment