Guest User

Minecraft Head Skin Switcher

a guest
Jan 18th, 2014
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.12 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import Image
  4. import sys
  5. import os.path
  6. import argparse
  7.  
  8. def switchHeadLayers(image):
  9.     #assume old skin dimension for the height of the head, 1/2 of the image y resultion
  10.     head_height = image.size[1] / 2
  11.  
  12.     #adjust for new skins, 14w03+ (1.8 style) 1/4 of the image y resolution
  13.     if image.size[0] == image.size[1]:
  14.         head_height = image.size[1] / 4
  15.  
  16.     box_head = (0, 0, image.size[0] / 2, head_height)
  17.     box_head_overlay = (image.size[0] / 2, 0, image.size[0], head_height)
  18.     original_head = image.crop(box_head)
  19.     original_overlay = image.crop(box_head_overlay)
  20.  
  21.     result = image.copy()
  22.     result.paste(original_overlay, box_head)
  23.     result.paste(original_head, box_head_overlay)
  24.  
  25.     return result
  26.  
  27. def switchHeadLayersByFilenameAndSave(filename_open, filename_save):
  28.     try:
  29.         original = Image.open(filename_open)
  30.         switched = switchHeadLayers(original)
  31.         switched.save(filename_save)
  32.         return True
  33.     except Exception as e:
  34.         print e
  35.         return False
  36.  
  37. if __name__ == "__main__":
  38.     description='''This will switch the overlay and head skin of any minecraft skin.'''
  39.     epilog='''If no output file is specified the switched skin will be saved in the same directory using the suffix "_switched". The same file format as the input file will be used.'''
  40.  
  41.     parser = argparse.ArgumentParser(description=description, epilog=epilog)
  42.     parser.add_argument("input", metavar='file', help="Input skin file")
  43.     parser.add_argument("-o","--output", metavar='file', help="Desired output skin file")
  44.     parser.add_argument("-s","--same", help="Use this if you want to replace the original file with the switched version.", action="store_true")
  45.     args = parser.parse_args()
  46.     loadFile = args.input
  47.  
  48.     if args.same and args.output:
  49.         print '-o and -s should not be used together. Flag -s will be obeyed.'
  50.    
  51.     if args.same:
  52.         saveFile = loadFile
  53.     else:
  54.         if args.output:
  55.             saveFile = args.output
  56.         else:
  57.             saveFile = os.path.splitext(args.input)[0] + "_switched" + os.path.splitext(args.input)[1]
  58.  
  59.     if switchHeadLayersByFilenameAndSave(loadFile, saveFile):
  60.         print "Saved switched skin: %s" % saveFile
  61.     else:
  62.         print "Something went wrong."
Advertisement
Add Comment
Please, Sign In to add comment