├── README.md └── pixel_art ├── README.md └── pixel_art.py /README.md: -------------------------------------------------------------------------------- 1 | # Stable Diffusion WebUI scripts 2 | 3 | Scripts for [AUTOMATIC1111's WebUI](https://github.com/AUTOMATIC1111/stable-diffusion-webui). 4 | 5 | - [Pixel Art](./pixel_art/) -------------------------------------------------------------------------------- /pixel_art/README.md: -------------------------------------------------------------------------------- 1 | # Pixel Art 2 | 3 | 4 | 5 | ## Examples: 6 | 7 | | Disabled | Enabled x8, no resize back, no color palette | Enabled x8, no color palette | Enabled x8, 16 color palette | 8 | | :---: | :---: | :---: | :---: | 9 | |![preview](https://user-images.githubusercontent.com/18114966/201491785-e30cfa9d-c850-4853-98b8-11db8de78c8d.png) | ![preview](https://user-images.githubusercontent.com/18114966/201492204-f4303694-e98d-4ea3-8256-538a88ea26b6.png) | ![preview](https://user-images.githubusercontent.com/18114966/201491864-d0c0c9f1-e34f-4cb6-a68e-7043ec5ce74e.png) | ![preview](https://user-images.githubusercontent.com/18114966/201492175-c55fa260-a17d-47c9-a919-9116e1caa8fe.png) | 10 | 11 | [model used](https://publicprompts.art/all-in-one-pixel-art-dreambooth-model/) 12 | ```text 13 | japanese pagoda with blossoming cherry trees, full body game asset, in pixelsprite style 14 | Steps: 20, Sampler: DDIM, CFG scale: 7, Seed: 4288895889, Size: 512x512, Model hash: 916ea38c, Batch size: 4 15 | ``` 16 | -------------------------------------------------------------------------------- /pixel_art/pixel_art.py: -------------------------------------------------------------------------------- 1 | import modules.scripts as scripts 2 | import gradio as gr 3 | 4 | from modules import images 5 | from modules.processing import process_images, Processed 6 | from modules.processing import Processed 7 | from modules.shared import opts, cmd_opts, state 8 | 9 | 10 | class Script(scripts.Script): 11 | def title(self): 12 | return "Pixel Art" 13 | def show(self, is_img2img): 14 | return True 15 | 16 | # How the script's is displayed in the UI. 17 | # The returned values are passed to the run method as parameters. 18 | def ui(self, is_img2img): 19 | from PIL import features 20 | 21 | downscale = gr.Slider(minimum=1, maximum=64, step=1, value=8, label="Downscale multiplier") 22 | rescale = gr.Checkbox(True, label="Rescale image back to original size") 23 | color_palette = gr.Slider(minimum=0, maximum=256, step=1, value=16, label="Color palette size (set to 0 to keep all colors)") 24 | palette_methods = ['Median cut', 'Maximum coverage', 'Fast octree'] 25 | if features.check_feature("libimagequant"): 26 | palette_methods.insert(0, "libimagequant") 27 | palette_method = gr.Radio(choices=palette_methods, value=palette_methods[0], label='Palette extraction method') 28 | return [downscale, rescale, color_palette, palette_method] 29 | 30 | 31 | 32 | # This is where the additional processing is implemented. The parameters include 33 | # self, the model object "p" (a StableDiffusionProcessing class, see 34 | # processing.py), and the parameters returned by the ui method. 35 | def run(self, p, downscale, rescale, color_palette, palette_method): 36 | from PIL import Image 37 | 38 | palette_methods = { 39 | "libimagequant": Image.Quantize.LIBIMAGEQUANT, 40 | "Median cut": Image.Quantize.MEDIANCUT, 41 | "Maximum coverage": Image.Quantize.MAXCOVERAGE, 42 | "Fast octree": Image.Quantize.FASTOCTREE 43 | } 44 | quantize = palette_methods.get(palette_method, None) 45 | 46 | # function which takes an image from the Processed object 47 | def process(im): 48 | # calculate sizes 49 | o_width, o_height = im.size 50 | s_width = int(o_width / downscale) 51 | s_height = int(o_height / downscale) 52 | 53 | raf = im 54 | raf = raf.resize((s_width, s_height), Image.NEAREST) 55 | 56 | if color_palette > 0: 57 | raf = raf.convert("RGB") 58 | raf = raf.quantize(colors=int(color_palette), method=quantize, dither=Image.Dither.FLOYDSTEINBERG) 59 | if rescale: 60 | raf = raf.resize((o_width, o_height), Image.NEAREST) 61 | 62 | return raf 63 | 64 | 65 | proc = process_images(p) 66 | # use the save_images method from images.py to save 67 | # them. 68 | for i in range(len(proc.images)): 69 | 70 | proc.images[i] = process(proc.images[i]) 71 | 72 | images.save_image(proc.images[i], p.outpath_samples, "", 73 | proc.seed + i, proc.prompt, opts.samples_format, info= proc.info, p=p) 74 | 75 | return proc 76 | --------------------------------------------------------------------------------