From 463d20999fa909c6f5c267eb8cdb22e3788a72c6 Mon Sep 17 00:00:00 2001 From: Daniel Tomlinson Date: Sun, 21 Mar 2021 00:11:52 +0000 Subject: [PATCH] updating extraction scripts --- .image-extraction/.gitignore | 140 +++++++++++++++++++++++++ .image-extraction/__init__.py | 0 .image-extraction/add_new_shikigami.md | 41 ++++++++ .image-extraction/extract_all.py | 52 +++++++++ .image-extraction/extract_character.py | 5 +- .image-extraction/extract_combat.py | 26 ++--- .image-extraction/extract_field.py | 5 +- .image-extraction/extract_form.py | 25 ++--- .image-extraction/extract_spell.py | 25 ++--- 9 files changed, 266 insertions(+), 53 deletions(-) create mode 100644 .image-extraction/.gitignore create mode 100644 .image-extraction/__init__.py create mode 100644 .image-extraction/add_new_shikigami.md create mode 100644 .image-extraction/extract_all.py diff --git a/.image-extraction/.gitignore b/.image-extraction/.gitignore new file mode 100644 index 0000000..4fdf691 --- /dev/null +++ b/.image-extraction/.gitignore @@ -0,0 +1,140 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + + diff --git a/.image-extraction/__init__.py b/.image-extraction/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/.image-extraction/add_new_shikigami.md b/.image-extraction/add_new_shikigami.md new file mode 100644 index 0000000..21b4f35 --- /dev/null +++ b/.image-extraction/add_new_shikigami.md @@ -0,0 +1,41 @@ +# Adding new Shikigami + +Remove all current images: + +`fd -e png -x rm {}**` + +After convert, copy to the character folder in assets: + +`fd -e png hououka -x mv {} /Users/dtomlinson/git-repos/web-dev/onmyoji-deck-builder/src/assets/cards/hououka` + +Print all cards (excluding char and avatar): + +`fd -E '*char*' -E '*avatar*'` + +Blank JSON template: + +- Paste template in +- Fill in with new char name +- Fill in filenames +- Copy `cards` +- Select all items in `cards` +- New line and paste to duplicate +- Update GUID + +```json + { + "name": "Hououka", + "character_card": "hououka/hououka-char.png", + "cards": [ + { "id": "d6fc26b2", "name": "", "url": "" }, + { "id": "1217f957", "name": "", "url": "" }, + { "id": "a507638d", "name": "", "url": "" }, + { "id": "a3e876ec", "name": "", "url": "" }, + { "id": "8fa65d84", "name": "", "url": "" }, + { "id": "914c6cbb", "name": "", "url": "" }, + { "id": "f1f8ce7d", "name": "", "url": "" }, + { "id": "1d30d350", "name": "", "url": "" }, + ], + "avatar": "hououka/hououka-avatar.png" + } +``` diff --git a/.image-extraction/extract_all.py b/.image-extraction/extract_all.py new file mode 100644 index 0000000..322e685 --- /dev/null +++ b/.image-extraction/extract_all.py @@ -0,0 +1,52 @@ +import glob + +import extract_combat +import extract_spell +import extract_form + +SHIKIGAMI_NAME = "ubume" + + +def main(shikigami_name: str): + # combat cards + for image in glob.glob( + "/Users/dtomlinson/git-repos/web-dev/onmyoji-deck-builder/." + "image-extraction/images/combat/*.*" + ): + print(image) + extract_combat.extract_image( + image, + "/Users/dtomlinson/git-repos/web-dev/onmyoji-deck-builder/." + "image-extraction/images/combat/out", + shikigami_name, + ) + + # spell cards + for image in glob.glob( + "/Users/dtomlinson/git-repos/web-dev/onmyoji-deck-builder/." + "image-extraction/images/spells/*.*" + ): + print(image) + extract_spell.extract_image( + image, + "/Users/dtomlinson/git-repos/web-dev/onmyoji-deck-builder/." + "image-extraction/images/spells/out", + shikigami_name, + ) + + # form cards + for image in glob.glob( + "/Users/dtomlinson/git-repos/web-dev/onmyoji-deck-builder/." + "image-extraction/images/forms/*.*" + ): + print(image) + extract_form.extract_image( + image, + "/Users/dtomlinson/git-repos/web-dev/onmyoji-deck-builder/." + "image-extraction/images/forms/out", + shikigami_name, + ) + + +if __name__ == "__main__": + main(SHIKIGAMI_NAME) diff --git a/.image-extraction/extract_character.py b/.image-extraction/extract_character.py index e0ab480..2c1afaf 100644 --- a/.image-extraction/extract_character.py +++ b/.image-extraction/extract_character.py @@ -65,6 +65,9 @@ def extract_image(filename: str, output_path: str) -> None: # convert back to an image extracted_image = Image.fromarray(extracted_image_array, "RGBA") + # crop + extracted_image = extracted_image.crop((533, 57, 769, 512)) + # save the image extracted_image.save(f"{output_path}/{filename.split('/')[-1].split('.')[-2]}.png") @@ -72,7 +75,7 @@ def extract_image(filename: str, output_path: str) -> None: if __name__ == "__main__": for image in glob.glob( "/Users/dtomlinson/git-repos/web-dev/onmyoji-deck-builder/." - "image-extraction/images/characters/in/*.*" + "image-extraction/images/characters/*.*" ): print(image) extract_image( diff --git a/.image-extraction/extract_combat.py b/.image-extraction/extract_combat.py index cfeeb25..83627c6 100644 --- a/.image-extraction/extract_combat.py +++ b/.image-extraction/extract_combat.py @@ -1,10 +1,8 @@ -import glob - import numpy from PIL import Image, ImageDraw -def extract_image(filename: str, output_path: str) -> None: +def extract_image(filename: str, output_path: str, shikigami_name: str) -> None: """ Extract a combat card from a screenshot from a device. Screenshot for each card taken from the Hyakabun scrollery. Image will be resized and the card extracted. @@ -60,19 +58,13 @@ def extract_image(filename: str, output_path: str) -> None: # convert back to an image extracted_image = Image.fromarray(extracted_image_array, "RGBA") + print(extracted_image.size) + + # crop + extracted_image = extracted_image.crop((495, 38, 788, 567)) # save the image - extracted_image.save(f"{output_path}/{filename.split('/')[-1].split('.')[-2]}.png") - - -if __name__ == "__main__": - for image in glob.glob( - "/Users/dtomlinson/git-repos/web-dev/onmyoji-deck-builder/." - "image-extraction/images/combat/in/*.*" - ): - print(image) - extract_image( - image, - "/Users/dtomlinson/git-repos/web-dev/onmyoji-deck-builder/." - "image-extraction/images/combat/out", - ) + extracted_image.save( + f"{output_path}/{shikigami_name}-" + f"{filename.split('/')[-1].split('.')[-2]}.png" + ) diff --git a/.image-extraction/extract_field.py b/.image-extraction/extract_field.py index 8e7555f..04e4eca 100644 --- a/.image-extraction/extract_field.py +++ b/.image-extraction/extract_field.py @@ -81,6 +81,9 @@ def extract_image(filename: str, output_path: str) -> None: # convert back to an image extracted_image = Image.fromarray(extracted_image_array, "RGBA") + # crop + extracted_image = extracted_image.crop((490, 42, 803, 568)) + # save the image extracted_image.save(f"{output_path}/{filename.split('/')[-1].split('.')[-2]}.png") @@ -88,7 +91,7 @@ def extract_image(filename: str, output_path: str) -> None: if __name__ == "__main__": for image in glob.glob( "/Users/dtomlinson/git-repos/web-dev/onmyoji-deck-builder/." - "image-extraction/images/fields/in/*.*" + "image-extraction/images/fields/*.*" ): print(image) extract_image( diff --git a/.image-extraction/extract_form.py b/.image-extraction/extract_form.py index 65c3f84..6306d0d 100644 --- a/.image-extraction/extract_form.py +++ b/.image-extraction/extract_form.py @@ -1,10 +1,8 @@ -import glob - import numpy from PIL import Image, ImageDraw -def extract_image(filename: str, output_path: str) -> None: +def extract_image(filename: str, output_path: str, shikigami_name: str) -> None: """ Extract a form card from a screenshot from a device. Screenshot for each card taken from the Hyakabun scrollery. Image will be resized and the card extracted. @@ -65,18 +63,11 @@ def extract_image(filename: str, output_path: str) -> None: # convert back to an image extracted_image = Image.fromarray(extracted_image_array, "RGBA") + # crop + extracted_image = extracted_image.crop((495, 39, 789, 567)) + # save the image - extracted_image.save(f"{output_path}/{filename.split('/')[-1].split('.')[-2]}.png") - - -if __name__ == "__main__": - for image in glob.glob( - "/Users/dtomlinson/git-repos/web-dev/onmyoji-deck-builder/." - "image-extraction/images/forms/in/*.*" - ): - print(image) - extract_image( - image, - "/Users/dtomlinson/git-repos/web-dev/onmyoji-deck-builder/." - "image-extraction/images/forms/out", - ) + extracted_image.save( + f"{output_path}/{shikigami_name}-" + f"{filename.split('/')[-1].split('.')[-2]}.png" + ) diff --git a/.image-extraction/extract_spell.py b/.image-extraction/extract_spell.py index 05f1227..6cefbfc 100644 --- a/.image-extraction/extract_spell.py +++ b/.image-extraction/extract_spell.py @@ -1,10 +1,8 @@ -import glob - import numpy from PIL import Image, ImageDraw -def extract_image(filename: str, output_path: str) -> None: +def extract_image(filename: str, output_path: str, shikigami_name: str) -> None: """ Extract a spell card from a screenshot from a device. Mask is valid for 1304x603 screenshot from an iPhone 12 Pro. @@ -59,18 +57,11 @@ def extract_image(filename: str, output_path: str) -> None: # convert back to an image extracted_image = Image.fromarray(extracted_image_array, "RGBA") + # crop + extracted_image = extracted_image.crop((496, 59, 788, 567)) + # save the image - extracted_image.save(f"{output_path}/{filename.split('/')[-1].split('.')[-2]}.png") - - -if __name__ == "__main__": - for image in glob.glob( - "/Users/dtomlinson/git-repos/web-dev/onmyoji-deck-builder/." - "image-extraction/images/spells/in/*.jpeg" - ): - print(image) - extract_image( - image, - "/Users/dtomlinson/git-repos/web-dev/onmyoji-deck-builder/." - "image-extraction/images/spells/out", - ) + extracted_image.save( + f"{output_path}/{shikigami_name}-" + f"{filename.split('/')[-1].split('.')[-2]}.png" + )