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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
| set icon_image to (choose file with prompt "请选择icon的原图,大小推荐1024x1024的:") as string
set output_path to (choose folder with prompt "请选择输出目录:") as string
set size_list to { {name:"icon-29.png", size:29, idiom_p:"iphone", scale_p:"1x"} }
set size_list to size_list & { {name:"icon-29@2x.png", size:29, idiom_p:"iphone", scale_p:"2x"} }
set size_list to size_list & { {name:"icon-29@3x.png", size:29, idiom_p:"iphone", scale_p:"3x"} }
set size_list to size_list & { {name:"icon-40@2x.png", size:40, idiom_p:"iphone", scale_p:"2x"} }
set size_list to size_list & { {name:"icon-40@3x.png", size:40, idiom_p:"iphone", scale_p:"3x"} }
set size_list to size_list & { {name:"icon-57.png", size:57, idiom_p:"iphone", scale_p:"1x"} }
set size_list to size_list & { {name:"icon-57@2x.png", size:57, idiom_p:"iphone", scale_p:"2x"} }
set size_list to size_list & { {name:"icon-60@2x.png", size:60, idiom_p:"iphone", scale_p:"2x"} }
set size_list to size_list & { {name:"icon-60@3x.png", size:60, idiom_p:"iphone", scale_p:"3x"} }
set size_list to size_list & { {name:"icon-29.png", size:29, idiom_p:"ipad", scale_p:"1x"} }
set size_list to size_list & { {name:"icon-29@2x.png", size:29, idiom_p:"ipad", scale_p:"2x"} }
set size_list to size_list & { {name:"icon-40.png", size:40, idiom_p:"ipad", scale_p:"1x"} }
set size_list to size_list & { {name:"icon-40@2x.png", size:40, idiom_p:"ipad", scale_p:"2x"} }
set size_list to size_list & { {name:"icon-50.png", size:50, idiom_p:"ipad", scale_p:"1x"} }
set size_list to size_list & { {name:"icon-50@2x.png", size:50, idiom_p:"ipad", scale_p:"2x"} }
set size_list to size_list & { {name:"icon-72.png", size:72, idiom_p:"ipad", scale_p:"1x"} }
set size_list to size_list & { {name:"icon-72@2x.png", size:72, idiom_p:"ipad", scale_p:"2x"} }
set size_list to size_list & { {name:"icon-76.png", size:76, idiom_p:"ipad", scale_p:"1x"} }
set size_list to size_list & { {name:"icon-76@2x.png", size:76, idiom_p:"ipad", scale_p:"2x"} }
set size_list to size_list & { {name:"icon-120.png", size:120, idiom_p:"car", scale_p:"1x"} }
set contents_json to "{
\"images\" : [
"
on removing folder items from output_path after losing these_items
end removing folder items from
on write_to_file(this_data, target_file, append_data) -- (string, file path as string, boolean)
try
set the target_file to the target_file as text
set the open_target_file to ¬
open for access file target_file with write permission
if append_data is false then ¬
set eof of the open_target_file to 0
write this_data to the open_target_file starting at eof
close access the open_target_file
return true
on error
try
close access file target_file
end try
return false
end try
end write_to_file
tell application "Image Events"
set total_count to the count of size_list
repeat with i from 1 to the count of size_list
set this_image to open icon_image
set info to (item i of size_list)
set result_name to the name of info
set result_size to the size of info
set the result_scale_p to the scale_p of info
if the result_scale_p is "3x" then
set result_size to result_size * 3
else if the result_scale_p is "2x" then
set result_size to result_size * 2
else
-- do nothing
end if
scale this_image to size result_size
save this_image in output_path & result_name
close this_image
-- add json format to contents
set size_value to the size of info as string
set size_value to size_value & "x" & size_value
set result_idiom to the idiom_p of info
set inner_json to "{
\"size\" : \"" & size_value & "\",
\"idiom\" : \"" & result_idiom & "\",
\"filename\" : \"" & result_name & "\",
\"scale\" : \"" & result_scale_p & "\"
}"
if i is less than total_count then
set inner_json to inner_json & ",
"
end if
set contents_json to contents_json & inner_json
end repeat
set contents_json to contents_json & "
]
}"
end tell
set file_path to output_path & "Contents.json"
my write_to_file(contents_json, file_path, false)
|