-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
53 lines (44 loc) · 1.21 KB
/
main.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# coding=utf-8
import json
import os
import sys
import shutil
from PIL import Image
from os import walk
# read finder url
dirName = sys.argv[1]
# read all files
f = []
for (dirpath, dirnames, filenames) in walk(dirName):
f.extend(filenames)
break
print f
# filter atlas files
for filename in f:
[name, type] = filename.split('.')
if type == 'atlas':
print '\n'
atlas = open(dirName + '/' + filename, 'r')
data = json.loads(atlas.read())
image_name = 'atlas/' + data['meta']['image']
path = 'dist/' + data['meta']['prefix']
print image_name
print path
# delete path
if os.path.exists(path):
shutil.rmtree(path)
# create path
os.makedirs(path)
# splice image
im = Image.open(image_name)
frames = data['frames']
for frame in frames:
frame_info = frames[frame]
x = frame_info['frame']['x']
y = frame_info['frame']['y']
w = frame_info['frame']['w']
h = frame_info['frame']['h']
print frame, x, y, w, h
box = (x, y, x + w, y + h)
region = im.crop(box)
region.save(path + frame)