Created
September 7, 2025 11:17
-
-
Save pixelomer/994bf26a19eb5ec4726835408206b72a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| # usage: extract-unity-sprites.py /path/to/spritesheet.png.meta | |
| import yaml | |
| import sys | |
| from PIL import Image | |
| def run_extract(meta): | |
| with open(meta, 'r') as f: | |
| map = yaml.safe_load(f) | |
| im = Image.open(meta.removesuffix(".meta")) | |
| print(im) | |
| for obj in map["TextureImporter"]["spriteSheet"]["sprites"]: | |
| rc = obj["rect"] | |
| rgn = (rc["x"], rc["y"], | |
| rc["x"] + rc["width"], | |
| rc["y"] + rc["height"]) | |
| print(rgn) | |
| sprite = im.crop(rgn) | |
| sprite.save(obj["name"] + ".png") | |
| if __name__ == '__main__': | |
| run_extract(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment