-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimagetiling.py
31 lines (27 loc) · 1.15 KB
/
imagetiling.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Thank you for checking out my project. Hope you like it. The comments might help you for understanding.
# Read the readme.md file for successful run of this program.
# ALL IMPORTS
from PIL import Image
import sys
# Function to split images in 5X5 grid.
def tileimage(image,count):
image = Image.open(image)
print(image.size[0],image.size[1])
tile_width = image.size[0]/5
tile_height = image.size[1]/5
if image.size[0] % tile_width == 0 and image.size[1] % tile_height ==0 :
currentx = 0
currenty = 0
offset = 5
while currenty < image.size[1]:
while currentx < image.size[0]:
## print (currentx,",",currenty)
tile = image.crop((currentx+offset,currenty+offset,currentx + tile_width - offset,currenty + tile_height - offset))
tile.save(str(count)+".png","PNG")
currentx += tile_width
count+=1
currenty += tile_height
currentx=0
else:
print ("sorry your image does not fit neatly into",
tile_width,"*",tile_height,"tiles")