Skip to content

Instantly share code, notes, and snippets.

@ryonagana
Created July 27, 2019 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryonagana/0503035e3ba8b92b4a56cf20718d2fcc to your computer and use it in GitHub Desktop.
Save ryonagana/0503035e3ba8b92b4a56cf20718d2fcc to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
"""
To Run This Script you 2 things
- use virtualenv
- install pillow (PIL fork for python 3.x) - pip install pillow
"""
import sys
import os
try:
from PIL import Image
except Exception as ex:
print("MODULE PILLOW NOT FOUND.. (type: pip install pillow)")
sys.exit(-1)
import getopt
from configparser import ConfigParser
def prepare_config(*args, **kwargs):
cfg = ConfigParser()
cfg['tileinfo'] = kwargs
with open(kwargs['name'] + ".ini", "w") as fp:
cfg.write(fp)
if __name__ == "__main__":
tilepath = None
width=0
height=0
offsetx=1
offsety=1
anim_x = 1
anim_y = 1
tile_width=16
tile_height=16
try:
opts,args = getopt.getopt(sys.argv[1:],'t:x:y:n:m:',['tileset=', 'offsetx=', 'offsety=',
'x_anim=', 'y_anim=', 'tile_width=', 'tile_height=' ])
for opt,data in opts:
if opt in ('-t', '--tileset'):
tilepath = data
if opt in ('--tile_width'):
tile_width=data
if opt in ('--tile_height'):
tile_height=data
try:
with Image.open(tilepath) as img:
width = img.size[0]
height = img.size[1]
print(width,height, tile_width, tile_height)
prepare_config(img_width=width,img_height=height,name=tilepath)
except Exception as ex:
print("1 - error:" + str(ex))
except Exception as e :
print("2 - error: " + str(e))
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment