Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys, os, png
- usage = "Transfers ZDoom/SLADE-format grAb chunk from donor to target PNGs.\n"\
- "Usage:\n\tpython.exe transfer_png_sprite_offsets.py donor target\n\n"\
- "Donor and target can either both be filenames or directories.\n"\
- "Subdirectories are not included."
- def do_the_thing(dnr_path, tgt_path):
- dnr_png = png.Reader(filename=dnr_path)
- tgt_png = png.Reader(filename=tgt_path)
- dnr_chunks = list(dnr_png.chunks())
- tgt_chunks = list(tgt_png.chunks())
- if dnr_chunks[1][0] == b'grAb':
- if tgt_chunks[1][0] != b'grAb':
- tgt_chunks.insert(1,dnr_chunks[1])
- with open(tgt_path, 'wb') as output:
- png.write_chunks(output, tgt_chunks)
- else:
- print("\nTarget already has offsets: " + name)
- else:
- input("\nNo donor offset chunk found: " + name)
- if len(sys.argv) != 3:
- input(usage)
- sys.exit()
- donor, target = sys.argv[1:3]
- if os.path.isfile(donor) and os.path.isfile(target):
- do_the_thing(donor, target)
- elif os.path.isdir(donor) and os.path.isdir(target):
- namelist = [f for (_,_,fnames) in os.walk(target) for f in fnames]
- for name in namelist:
- donor_path = os.path.join(donor, name)
- target_path = os.path.join(target, name)
- if os.path.isfile(donor_path):
- do_the_thing(donor_path, target_path)
- else:
- print("\nCould not find a matching donor: " + name)
- else:
- input(usage)
- sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment