Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import Image
- import sys
- import os.path
- import argparse
- def switchHeadLayers(image):
- #assume old skin dimension for the height of the head, 1/2 of the image y resultion
- head_height = image.size[1] / 2
- #adjust for new skins, 14w03+ (1.8 style) 1/4 of the image y resolution
- if image.size[0] == image.size[1]:
- head_height = image.size[1] / 4
- box_head = (0, 0, image.size[0] / 2, head_height)
- box_head_overlay = (image.size[0] / 2, 0, image.size[0], head_height)
- original_head = image.crop(box_head)
- original_overlay = image.crop(box_head_overlay)
- result = image.copy()
- result.paste(original_overlay, box_head)
- result.paste(original_head, box_head_overlay)
- return result
- def switchHeadLayersByFilenameAndSave(filename_open, filename_save):
- try:
- original = Image.open(filename_open)
- switched = switchHeadLayers(original)
- switched.save(filename_save)
- return True
- except Exception as e:
- print e
- return False
- if __name__ == "__main__":
- description='''This will switch the overlay and head skin of any minecraft skin.'''
- 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.'''
- parser = argparse.ArgumentParser(description=description, epilog=epilog)
- parser.add_argument("input", metavar='file', help="Input skin file")
- parser.add_argument("-o","--output", metavar='file', help="Desired output skin file")
- parser.add_argument("-s","--same", help="Use this if you want to replace the original file with the switched version.", action="store_true")
- args = parser.parse_args()
- loadFile = args.input
- if args.same and args.output:
- print '-o and -s should not be used together. Flag -s will be obeyed.'
- if args.same:
- saveFile = loadFile
- else:
- if args.output:
- saveFile = args.output
- else:
- saveFile = os.path.splitext(args.input)[0] + "_switched" + os.path.splitext(args.input)[1]
- if switchHeadLayersByFilenameAndSave(loadFile, saveFile):
- print "Saved switched skin: %s" % saveFile
- else:
- print "Something went wrong."
Advertisement
Add Comment
Please, Sign In to add comment