The actual operation is very technical, but would like to show the Almighty Python. Although I am disgusted with the text encoding and whitespace alignment of Python, I have to say that its interface design is excellent, making complex work very simple, and this idea is reflected in the third-party extension.
Turret legend uses the form of jpg+mask files to achieve the purpose of compressing resources. The compression ratio of JPG is excellent, and mask contains transparent channel information, so that the image size can be greatly compressed.
However, I personally prefer PNG, using png8+ compression texture is not worse than this scheme, in exchange for faster loading speed and memory savings. Especially in unity, I prefer unity to manage textures, rather than worrying about myself.
#coding: Utf-8import os;from PIL import image;# convert mask+jpg files in turret legend to PNG files def doconvertjpg (Jpgpath, Maskpath): Pngpath = Jpgpath.replace ('. jpg ', '. png '); Maskdata = open (Maskpath, ' RB '). read (); Jpgdata = open (Jpgpath, ' RB '). read (); JPG = Image.open (jpgpath); width = jpg.size[0]; Height = jpg.size[1]; PNG = Jpg.convert (' RGBA ') mask = Image.open (Maskpath); Png.putalpha (mask); Png.save (Pngpath); Os.remove (Jpgpath); Os.remove (maskpath);d EF doconvertpath (path): for Root, dirs, files on Os.walk (path): For file in files: If File.find ('. jpg ')! =-1: FullPath = os.path.join (root, file); Maskpath = Fullpath.replace ('. jpg ', ' _alpha_mask '); If Os.path.exists (maskpath): doconvertjpg (FullPath, Maskpath);d oconvertpath (' UI '); Os.system (' PAUSE ')
The most magical is the Image.putalpha function, which has done all the work that needs to be done.
Convert the Jpg+mask file in the turret legend to a PNG file with transparent channels