Skip to content

Commit

Permalink
Merge pull request #1 from rysuds/refactor
Browse files Browse the repository at this point in the history
refactored and added cli command + group samples as an example
  • Loading branch information
rysuds committed Jun 6, 2020
2 parents 1450af0 + baf2324 commit 38a4979
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 9 deletions.
Binary file removed .DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ __pycache__/
*.py[cod]
*$py.class

*.DS_Store

# C extensions
*.so

Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
# exsprite
A CLI tool for extracting sprites from spritesheets!

## Setup
This will install all required packages and create the cli command for use
```
python setup.py install
```

## Example usage

If you want to group your sprite sheet by rows do

```
~$ python exprite.py --filename <filename> save
exsprite --filename <path to sprite sheet> save
```
File renamed without changes.
9 changes: 9 additions & 0 deletions exsprite/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from exsprite.core import SpriteSheet

import fire

def main():
fire.Fire(SpriteSheet)

if __name__ == '__main__':
main()
3 changes: 3 additions & 0 deletions exsprite/core/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from exsprite.core.sprite_sheet import SpriteSheet

__all__ = ["SpriteSheet"]
13 changes: 5 additions & 8 deletions exsprite.py → exsprite/core/sprite_sheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from PIL import Image
import cv2
import fire
from utils import show, unique, filter_bounds, get_bounds
from exsprite.utils import show, unique, filter_bounds, get_bounds


def get_chunk(tup, labeled):
Expand Down Expand Up @@ -50,7 +50,7 @@ def __init__(self, filename, background=0):
self.labeled_image=None
self._get_boolean_image()
self._get_labeled_image()

def _get_boolean_image(self):
background = flood(self.img[..., 0], (0,0), tolerance=0.0)
self.img[background] = 0
Expand All @@ -61,7 +61,7 @@ def _get_labeled_image(self):
labeled, ncomponents = label(self.boolean_image, structure)
self.labeled_image = labeled
self.num_labels = ncomponents

def _get_sprite_groups(self):
print(self.boolean_image)
bound_tups = filter_bounds(get_bounds(self.boolean_image))
Expand All @@ -74,7 +74,7 @@ def _check_create_folder(self,foldername=None):
if foldername not in set(os.listdir()):
os.mkdir(foldername)
return foldername

def save(self):
sprite_groups = self._get_sprite_groups()
self._check_create_folder()
Expand All @@ -86,10 +86,7 @@ def save(self):
raw_inds = np.where(self.labeled_image==label)
rrow, rcol = raw_inds
minr, maxr = int(min(rrow)), int(max(rrow))
minc, maxc = int(min(rcol)), int(max(rcol))
minc, maxc = int(min(rcol)), int(max(rcol))
sub_image = self.img[minr:maxr+1,minc:maxc+1]
#show(sub_image,50)
io.imsave(filename,sub_image)

if __name__ == '__main__':
fire.Fire(SpriteSheet)
1 change: 1 addition & 0 deletions exsprite/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from exsprite.utils.utils import *
File renamed without changes.
41 changes: 41 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

"""The setup script."""

from setuptools import setup, find_packages

with open('README.md') as readme_file:
readme = readme_file.read()

requirements = ['numpy',
'Pillow',
'scikit-image',
'scipy',
'opencv-python',
'fire',
'matplotlib'
]

setup(
author="Ryan Sudhakaran",
python_requires='>=3.8',
classifiers=[
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
],
description="A CLI tool for extracting sprites from spritesheets!",
entry_points={
'console_scripts': [
'exsprite=exsprite.cli:main',
],
},
install_requires=requirements,
license="Apache Software License 2.0",
long_description=readme,
include_package_data=True,
keywords='exsprite',
name='exsprite',
packages=find_packages(include=['exsprite', 'exsprite.*']),
url='https://github.com/rysuds/exsprite',
version='0.1.0',
zip_safe=False,
)

0 comments on commit 38a4979

Please sign in to comment.