SHARE
TWEET

Majora's Mask - icon2image

Faschz May 21st, 2019 (edited) 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import cv2
  2. import numpy
  3. import os
  4.  
  5. def main():
  6.     # Converts the entire directory of icons into a directory of .png images
  7.     # that can be viewed
  8.     for f in os.listdir('/icon/'):
  9.         # This will read the file into a numpy array that OpenCV can use
  10.         # to manipulate and convert into an image of the appropriate format
  11.         img = numpy.fromfile(f, dtype='uint8')
  12.        
  13.         # The icons are 32x32 RGBA images
  14.         img = img.reshape((32, 32, 4))
  15.        
  16.         # OpenCV saves the images as BGRA, but Majora's Mask has the icons
  17.         # as RGBA. This will convert them to the correct format
  18.         img = cv2.cvtColor(img, cv2.COLOR_RGBA2BGRA)
  19.        
  20.         # The output should be the same filename, but instead it is a '.png'
  21.         # instead of a '.bin'
  22.         cv2.imwrite('/image/' + f[-3] + 'png', img)
  23.    
  24. if __name__ == "__main__":
  25.     main()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top