forked from credomane/FactorioMods_FactorioMaps
-
Notifications
You must be signed in to change notification settings - Fork 2
/
compress.py
36 lines (21 loc) · 879 Bytes
/
compress.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
from PIL import Image
import multiprocessing as mp
import os, math, sys, time, psutil
from functools import partial
ext = ".png"
def convert(path):
Image.open(path + ".png", mode='r').convert('RGB').save(path + ".jpg", format='JPEG') #, subsampling=0, quality=100)
os.remove(path + ".png")
if __name__ == '__main__':
toppath = (sys.argv[1] if len(sys.argv) > 2 else "../../script-output/FactorioMaps/new") + "/"
maxthreads = mp.cpu_count()
print(toppath)
allImages = []
for root, _, files in os.walk(toppath):
for file in files:
splitExt = os.path.splitext(os.path.join(root, file))
if splitExt[1] == ".png":
allImages.append(splitExt[0])
print("converting %s images to jpg" % len(allImages))
pool = mp.Pool(processes=maxthreads)
pool.map(convert, allImages, 128)