Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
AlUlkesh committed Jan 1, 2023
0 parents commit 901bd1d
Show file tree
Hide file tree
Showing 7 changed files with 218 additions and 0 deletions.
129 changes: 129 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# 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/
pip-wheel-metadata/
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/

# 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
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.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/
24 changes: 24 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <http://unlicense.org/>
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Stable Diffusion extension: Add the image's number to its picture in the grid

A custom extension for [AUTOMATIC1111/stable-diffusion-webui](https://github.com/AUTOMATIC1111/stable-diffusion-webui) to add the image's number to its picture in the grid.

After choosing a new grid option in the settings:
<img src="images/settings.jpg"/>

the individual image numbers are added on the grid:
<img src="images/grid-1517-123-stickman.jpg"/>
<img src="images/xy_grid-0137-123-stickman.jpg"/>

This should make identifying the images, especially in larger batches, much easier.

## Installation

The extension can be installed directly from within the **Extensions** tab within the Webui.

You can also install it manually by running the following command from within the webui directory:

git clone https://github.com/AlUlkesh/sd_grid_add_image_number/ extensions/sd_grid_add_image_number
Binary file added images/grid-1517-123-stickman.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/settings.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/xy_grid-0137-123-stickman.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 45 additions & 0 deletions scripts/sd_grid_add_image_number.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from modules import scripts
from modules import script_callbacks
from modules.processing import Processed
from modules.shared import opts, OptionInfo
from fonts.ttf import Roboto
from PIL import Image, ImageFont, ImageDraw
import os

# Add option to settings
def on_ui_settings():
opts.add_option("sd_grid_add_image_number", OptionInfo(True, "Add the image's number to its picture in the grid (when 'Add number to filename' is on)", section=("saving-images", "Saving images/grids")))
script_callbacks.on_ui_settings(on_ui_settings)

# Insert individual image number, lower left corner, in front of a box
def handle_image_grid_loop(img : script_callbacks.ImageGridLoopParams):
if opts.sd_grid_add_image_number and opts.save_images_add_number and opts.samples_save and hasattr(img, "already_saved_as"):
img_filename = os.path.basename(img.already_saved_as)
img_filename_split = img_filename.split('-')
img_num_text = img_filename_split[0]

if img_num_text.isdigit():
img_num_draw = ImageDraw.Draw(img)
img_num_font = ImageFont.truetype(Roboto, 24)
img_num_color = (255, 255, 255)
img_num_box_color = (0, 0, 0)
img_num_distance = 10

_, img_num_height = img.size
img_num_text_width, img_num_text_height = img_num_draw.textsize(img_num_text, font=img_num_font)

img_num_box_x = img_num_distance
img_num_box_y = img_num_height - img_num_distance
img_num_box_width = img_num_text_width + img_num_distance * 2
img_num_box_height = img_num_text_height + img_num_distance * 2
img_num_box_x1 = img_num_box_x
img_num_box_y1 = img_num_box_y - img_num_box_height
img_num_box_x2 = img_num_box_x + img_num_box_width
img_num_box_y2 = img_num_box_y

img_num_x = img_num_box_x + img_num_box_width // 2 - img_num_text_width // 2
img_num_y = img_num_box_y - img_num_box_height // 2 - img_num_text_height // 2

img_num_draw.rectangle((img_num_box_x1, img_num_box_y1, img_num_box_x2, img_num_box_y2), fill=img_num_box_color)
img_num_draw.text((img_num_x, img_num_y), img_num_text, font=img_num_font, fill=img_num_color)
script_callbacks.on_image_grid_loop(handle_image_grid_loop)

0 comments on commit 901bd1d

Please sign in to comment.