MCPcopy Create free account
hub / github.com/SimHacker/micropolis / ChopTiles

Function ChopTiles

MicropolisCore/src/CellEngine/python/convert-tiles.py:84–114  ·  view source on GitHub ↗
(fileName, newFileName, oldcols, newcols)

Source from the content-addressed store, hash-verified

82newim = None
83
84def ChopTiles(fileName, newFileName, oldcols, newcols):
85 global im, newim
86 im = Image.open(fileName)
87 width, height = im.size
88 print "NEWCOLS", newcols
89 print "WIDTH", width, "HEIGHT", height
90 cols = 1
91 rows = height / width
92 print fileName, width, height, im
93
94 newwidth = width * newcols
95 newheight = int(math.ceil(height / newcols))
96 newrows = newheight / width
97
98 print "NEWWIDTH", newwidth, "NEWHEIGHT", newheight, "NEWCOLS", newcols, "NEWROWS", newrows
99
100 newim = Image.new(im.mode, (newwidth, newheight))
101
102 for cell in range(0, newrows * newcols):
103 oldcol = int(cell % oldcols)
104 oldrow = int(math.floor(cell / oldcols))
105 frombox = (0, cell * width, width, (cell + 1) * width)
106
107 newcol = int(cell % newcols)
108 newrow = int(math.floor(cell / newcols))
109 tobox = (newcol * width, newrow * width, (newcol + 1) * width, (newrow + 1) * width)
110
111 tile = im.crop(frombox)
112 newim.paste(tile, tobox)
113
114 newim.save(newFileName)
115
116
117def main():

Callers 1

mainFunction · 0.85

Calls 1

saveMethod · 0.45

Tested by

no test coverage detected