-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathresize.py
More file actions
462 lines (357 loc) · 14.5 KB
/
resize.py
File metadata and controls
462 lines (357 loc) · 14.5 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
import csv
import multiprocessing
import os
import os.path
import requests
import shutil
from PIL import Image
DOWNLOAD_URL = 'http://localhost:59000/casc/fdid?fileDataID=%s&filename=%s'
SIZES = [
16,
20,
24,
32,
40,
48,
56,
]
SUBDIRS = [
'achievement',
'affix',
'class',
'currency',
'enchantment',
'garrison-talent',
'item',
'mount',
'npc',
'spec',
'spell',
'trait-node',
]
ITEM_OVERRIDE = {
178708: 838551, # Unbound Changeling -> inv_pet_spectralporcupinered
}
CLASS_OVERRIDE = {
12: 1260827, # Demon Hunter -> classicon_demonhunter
}
for size in SIZES:
s = str(size)
if not os.path.isdir(s):
os.mkdir(s)
for subdir in SUBDIRS:
p = os.path.join(s, subdir)
if not os.path.isdir(p):
os.mkdir(p)
def resize_and_save(filepath, outputs):
with counter.get_lock():
counter.value += 1
if counter.value % 100 == 0:
print(counter.value)
im = None
try:
im = Image.open(filepath)
if im.size != (64, 64):
im = im.resize((64, 64), Image.Resampling.LANCZOS)
# source icons have a dumb border
im = im.crop((4, 4, 60, 60))
except Exception as e:
print('!! UH OH !!', filepath, e)
return
for size in SIZES:
resized = im.copy()
resized.thumbnail((size, size), Image.Resampling.LANCZOS)
size_str = str(size)
for folder, filedata_ids in outputs:
# print(f'Saving {len(filedata_ids)} to {folder}')
maybe_save(filedata_ids, resized, size_str, folder)
def maybe_save(ids, img, outdir, prefix):
outfile = '%s.png' % (ids[0])
outpath = os.path.join(outdir, prefix, outfile)
if not os.path.exists(outpath):
img.save(outpath)
for id in ids[1:]:
linkname = '%s.png' % (id)
if linkname in existing[size]:
continue
linkpath = os.path.join(outdir, prefix, linkname)
if linkpath in existing[size]:
continue
try:
os.symlink(outfile, linkpath)
except:
pass
if __name__ == '__main__':
base_path = os.path.join(os.path.abspath(os.path.expanduser(os.environ['WOWTHING_DUMP_PATH'])), 'enUS')
# custom images
for filename in sorted(os.listdir('raw')):
filepath = os.path.join('raw', filename)
im = Image.open(filepath)
im = im.crop((3, 3, im.width - 3, im.height - 3))
print('Processing', filepath, im.size)
for size in SIZES:
sizePath = os.path.join(str(size), filename)
if not os.path.exists(sizePath):
resized = im.copy()
resized.thumbnail((size, size), Image.Resampling.LANCZOS)
resized.save(sizePath)
print('----')
existing = {}
existing['blp'] = set(os.listdir('blp'))
existing['decor'] = set(os.listdir('decor_raw'))
for size in SIZES:
s = str(size)
existing[size] = set(os.listdir(s))
for subdir in SUBDIRS:
p = os.path.join(s, subdir)
existing[size] = existing[size] | set(os.path.join(subdir, sigh) for sigh in os.listdir(p))
filedata_ids = set()
# achievement
achievements = {}
with open(os.path.join(base_path, os.path.join(base_path), 'achievement.csv'), newline='') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
achievements.setdefault(int(row['IconFileID']), []).append(int(row['ID']))
print('Loaded achievement')
# battlepetspecies
pets = {}
with open(os.path.join(base_path, 'battlepetspecies.csv'), newline='') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
pets.setdefault(int(row['IconFileDataID']), []).append(int(row['CreatureID']))
print('Loaded battlepetspecies')
# chrclasses
classes = {}
with open(os.path.join(base_path, 'chrclasses.csv'), newline='') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
id = int(row['ID'])
classes.setdefault(CLASS_OVERRIDE.get(id, int(row['IconFileDataID'])), []).append(id)
print('Loaded chrclasses')
# chrspecialization
specs = {}
with open(os.path.join(base_path, 'chrspecialization.csv'), newline='') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
specs.setdefault(int(row['SpellIconFileID']), []).append(int(row['ID']))
print('Loaded chrspecialization')
# currencytypes
currencies = {}
with open(os.path.join(base_path, 'currencytypes.csv'), newline='') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
currencies.setdefault(int(row['InventoryIconFileID']), []).append(int(row['ID']))
print('Loaded currencytypes')
# garrtalent
garrtalents = {}
with open(os.path.join(base_path, 'garrtalent.csv'), newline='') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
garrtalents.setdefault(int(row['IconFileDataID']), []).append(int(row['ID']))
print('Loaded garrtalent')
# item
items = {}
item_to_filedata = {}
with open(os.path.join(base_path, 'item.csv'), newline='') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
id = int(row['ID'])
filedata_id = ITEM_OVERRIDE.get(id, int(row['IconFileDataID']))
items.setdefault(filedata_id, []).append(id)
item_to_filedata[id] = filedata_id
print('Loaded item')
# itemappearance
appearance_to_filedata = {}
with open(os.path.join(base_path, 'itemappearance.csv'), newline='') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
id = int(row['ID'])
# Warglaives of Azzinoth are very weird
if id in (8460, 8461, 34777):
print('hackerman')
appearance_to_filedata[id] = 135561
else:
appearance_to_filedata[id] = int(row['DefaultIconFileDataID'])
print('Loaded itemappearance')
# itemmodifiedappearance
item_modified_appearances = {}
with open(os.path.join(base_path, 'itemmodifiedappearance.csv'), newline='') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
item_id = int(row['ItemID'])
order = int(row['OrderIndex'])
modifier_id = int(row['ItemAppearanceModifierID'])
appearance_id = int(row['ItemAppearanceID'])
# hack Warglaives of Azzinoth to point to the newer appearance ID
if item_id in (32837, 32838):
print('hackerman2')
appearance_id = 34777
item_modified_appearances.setdefault(item_id, []).append([
order,
modifier_id,
appearance_id,
])
for item_id, imas in item_modified_appearances.items():
first = True
for order, modifier_id, appearance_id in sorted(imas):
#print(order, modifier_id, appearance_id)
if appearance_id in appearance_to_filedata:
ima_filedata = appearance_to_filedata[appearance_id]
if first:
items.setdefault(ima_filedata, []).append(item_id)
item_to_filedata[item_id] = ima_filedata
first = False
if modifier_id > 0:
#print('eyyy', order, modifier_id, appearance_id)
items.setdefault(ima_filedata, []).append(f'{item_id}_{modifier_id}')
print('Loaded itemmodifiedappearance')
# keystoneaffix
affixes = {}
with open(os.path.join(base_path, 'keystoneaffix.csv'), newline='') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
affixes.setdefault(int(row['FiledataID']), []).append(int(row['ID']))
print('Loaded keystoneaffix')
# spellitemenchantment
enchantments = {}
with open(os.path.join(base_path, 'spellitemenchantment.csv'), newline='') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
enchantments.setdefault(int(row['IconFileDataID']), []).append(int(row['ID']))
print('Loaded spellitemenchantment')
# spellmisc
spells = {}
spell_to_filedata = {}
with open(os.path.join(base_path, 'spellmisc.csv'), newline='') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
spell_id = int(row['SpellID'])
if spell_id == 0:
continue
filedata_id = int(row['SpellIconFileDataID'])
if filedata_id == 0:
continue
spells.setdefault(filedata_id, []).append(spell_id)
spell_to_filedata[spell_id] = filedata_id
print('Loaded spellmisc')
# toy
toys = {}
with open(os.path.join(base_path, 'toy.csv'), newline='') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
item_id = int(row['ItemID'])
if item_id in item_to_filedata:
toys.setdefault(item_to_filedata[item_id], []).append(item_id)
print('Loaded toy')
# traitdefinition
trait_definitions = {}
with open(os.path.join(base_path, 'traitdefinition.csv'), newline='') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
trait_definition_id = int(row['ID'])
override_icon = int(row['OverrideIcon'])
spell_id = int(row['SpellID'])
visible_spell_id = int(row['VisibleSpellID'])
if spell_id or override_icon or visible_spell_id:
trait_definitions[trait_definition_id] = [spell_id, override_icon, visible_spell_id]
print('Loaded traitdefinition')
# traitnodeentry
trait_nodes = {}
with open(os.path.join(base_path, 'traitnodeentry.csv'), newline='') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
trait_node_id = int(row['ID'])
trait_definition_id = int(row['TraitDefinitionID'])
if trait_definition_id not in trait_definitions:
continue
spell_id, override_icon, visible_spell_id = trait_definitions[int(row['TraitDefinitionID'])]
if override_icon:
trait_nodes.setdefault(override_icon, []).append(trait_node_id)
elif visible_spell_id and visible_spell_id in spell_to_filedata:
trait_nodes.setdefault(spell_to_filedata[visible_spell_id], []).append(trait_node_id)
elif spell_id in spell_to_filedata:
trait_nodes.setdefault(spell_to_filedata[spell_id], []).append(trait_node_id)
print('Loaded traitnodeentry')
# load filedata
filedata = {}
with open(os.path.join(base_path, 'manifestinterfacedata.csv'), newline='') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
id = int(row['ID'])
if id in achievements or \
id in affixes or \
id in classes or \
id in currencies or \
id in enchantments or \
id in garrtalents or \
id in items or \
id in pets or \
id in specs or \
id in spells or \
id in toys or \
id in trait_nodes:
filedata[id] = row['FileName'].lower()
print('Found %d valid filedatas' % len(filedata))
# load listfile
with open('listfile.csv', newline='') as csvfile:
reader = csv.reader(csvfile, delimiter=';')
for id, filepath in reader:
id = int(id)
if id in achievements or id in currencies or id in pets or id in spells or id in toys or id in items:
if id not in filedata and filepath.startswith('interface/icons/') and filepath.endswith('.blp'):
filedata[id] = filepath.replace('interface/icons/', '')
print(f'listfile: {id} => {filedata[id]}')
# try to download any missing files from wow.tools.local
for id in items:
if id > 0 and id not in filedata:
maybe_filename = f'{id}.blp'
if maybe_filename not in existing['blp']:
url = DOWNLOAD_URL % (id, maybe_filename)
with requests.get(url, stream=True) as response:
if response.status_code != 200:
print(f'Download failed {maybe_filename} => {response.status_code}')
continue
print(f'Downloaded {maybe_filename}')
blp_path = os.path.join('blp', maybe_filename)
with open(blp_path, 'wb') as out_file:
shutil.copyfileobj(response.raw, out_file)
filedata[id] = maybe_filename
global counter
counter = multiprocessing.Value('i', 0)
queue = []
for filedata_id in filedata:
filename = filedata.get(filedata_id)
if not filename:
print('Missing filedata: %s' % (filedata_id))
continue
if filename not in existing['blp']:
print('Filedata %s missing file: %s' % (filedata_id, filename))
continue
filepath = os.path.join('blp', filename)
save_as = []
if filedata_id in achievements:
save_as.append(['achievement', achievements[filedata_id]])
if filedata_id in affixes:
save_as.append(['affix', affixes[filedata_id]])
if filedata_id in classes:
save_as.append(['class', classes[filedata_id]])
if filedata_id in currencies:
save_as.append(['currency', currencies[filedata_id]])
if filedata_id in enchantments:
save_as.append(['enchantment', enchantments[filedata_id]])
if filedata_id in garrtalents:
save_as.append(['garrison-talent', garrtalents[filedata_id]])
if filedata_id in items:
save_as.append(['item', items[filedata_id]])
if filedata_id in pets:
save_as.append(['npc', pets[filedata_id]])
if filedata_id in specs:
save_as.append(['spec', specs[filedata_id]])
if filedata_id in spells:
save_as.append(['spell', spells[filedata_id]])
if filedata_id in trait_nodes:
save_as.append(['trait-node', trait_nodes[filedata_id]])
queue.append([filepath, save_as])
count = 0
with multiprocessing.Pool() as pool:
pool.starmap(resize_and_save, queue)