We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[Feature Request]: img2img batch should ignore non-image files
### Is there an existing issue for this?

- [X] I have searched the existing issues and checked the recent builds/commits

### What would your feature do ?

I may place some parameter files along the image files in the same folder.
Currently an exception is throw for non-image files when do "Image.open()".

### Proposed workflow

1. Place a txt file along with the png file in folder A
2. Set batch input folder to A
3. Press generate


### Additional information

_No response_

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `modules/img2img.py`
Content:
```
1 import math
2 import os
3 import sys
4 import traceback
5 
6 import numpy as np
7 from PIL import Image, ImageOps, ImageFilter, ImageEnhance, ImageChops, UnidentifiedImageError
8 
9 from modules import devices, sd_samplers
10 from modules.generation_parameters_copypaste import create_override_settings_dict
11 from modules.processing import Processed, StableDiffusionProcessingImg2Img, process_images
12 from modules.shared import opts, state
13 import modules.shared as shared
14 import modules.processing as processing
15 from modules.ui import plaintext_to_html
16 import modules.images as images
17 import modules.scripts
18 
19 
20 def process_batch(p, input_dir, output_dir, inpaint_mask_dir, args):
21     processing.fix_seed(p)
22 
23     images = shared.listfiles(input_dir)
24 
25     is_inpaint_batch = False
26     if inpaint_mask_dir:
27         inpaint_masks = shared.listfiles(inpaint_mask_dir)
28         is_inpaint_batch = len(inpaint_masks) > 0
29     if is_inpaint_batch:
30         print(f"\nInpaint batch is enabled. {len(inpaint_masks)} masks found.")
31 
32     print(f"Will process {len(images)} images, creating {p.n_iter * p.batch_size} new images for each.")
33 
34     save_normally = output_dir == ''
35 
36     p.do_not_save_grid = True
37     p.do_not_save_samples = not save_normally
38 
39     state.job_count = len(images) * p.n_iter
40 
41     for i, image in enumerate(images):
42         state.job = f"{i+1} out of {len(images)}"
43         if state.skipped:
44             state.skipped = False
45 
46         if state.interrupted:
47             break
48 
49         try:
50             img = Image.open(image)
51         except UnidentifiedImageError:
52             continue
53         # Use the EXIF orientation of photos taken by smartphones.
54         img = ImageOps.exif_transpose(img)
55         p.init_images = [img] * p.batch_size
56 
57         if is_inpaint_batch:
58             # try to find corresponding mask for an image using simple filename matching
59             mask_image_path = os.path.join(inpaint_mask_dir, os.path.basename(image))
60             # if not found use first one ("same mask for all images" use-case)
61             if not mask_image_path in inpaint_masks:
62                 mask_image_path = inpaint_masks[0]
63             mask_image = Image.open(mask_image_path)
64             p.image_mask = mask_image
65 
66         proc = modules.scripts.scripts_img2img.run(p, *args)
67         if proc is None:
68             proc = process_images(p)
69 
70         for n, processed_image in enumerate(proc.images):
71             filename = os.path.basename(image)
72 
73             if n > 0:
74                 left, right = os.path.splitext(filename)
75                 filename = f"{left}-{n}{right}"
76 
77             if not save_normally:
78                 os.makedirs(output_dir, exist_ok=True)
79                 if processed_image.mode == 'RGBA':
80                     processed_image = processed_image.convert("RGB")
81                 processed_image.save(os.path.join(output_dir, filename))
82 
83 
84 def img2img(id_task: str, mode: int, prompt: str, negative_prompt: str, prompt_styles, init_img, sketch, init_img_with_mask, inpaint_color_sketch, inpaint_color_sketch_orig, init_img_inpaint, init_mask_inpaint, steps: int, sampler_index: int, mask_blur: int, mask_alpha: float, inpainting_fill: int, restore_faces: bool, tiling: bool, n_iter: int, batch_size: int, cfg_scale: float, image_cfg_scale: float, denoising_strength: float, seed: int, subseed: int, subseed_strength: float, seed_resize_from_h: int, seed_resize_from_w: int, seed_enable_extras: bool, selected_scale_tab: int, height: int, width: int, scale_by: float, resize_mode: int, inpaint_full_res: bool, inpaint_full_res_padding: int, inpainting_mask_invert: int, img2img_batch_input_dir: str, img2img_batch_output_dir: str, img2img_batch_inpaint_mask_dir: str, override_settings_texts, *args):
85     override_settings = create_override_settings_dict(override_settings_texts)
86 
87     is_batch = mode == 5
88 
89     if mode == 0:  # img2img
90         image = init_img.convert("RGB")
91         mask = None
92     elif mode == 1:  # img2img sketch
93         image = sketch.convert("RGB")
94         mask = None
95     elif mode == 2:  # inpaint
96         image, mask = init_img_with_mask["image"], init_img_with_mask["mask"]
97         alpha_mask = ImageOps.invert(image.split()[-1]).convert('L').point(lambda x: 255 if x > 0 else 0, mode='1')
98         mask = ImageChops.lighter(alpha_mask, mask.convert('L')).convert('L')
99         image = image.convert("RGB")
100     elif mode == 3:  # inpaint sketch
101         image = inpaint_color_sketch
102         orig = inpaint_color_sketch_orig or inpaint_color_sketch
103         pred = np.any(np.array(image) != np.array(orig), axis=-1)
104         mask = Image.fromarray(pred.astype(np.uint8) * 255, "L")
105         mask = ImageEnhance.Brightness(mask).enhance(1 - mask_alpha / 100)
106         blur = ImageFilter.GaussianBlur(mask_blur)
107         image = Image.composite(image.filter(blur), orig, mask.filter(blur))
108         image = image.convert("RGB")
109     elif mode == 4:  # inpaint upload mask
110         image = init_img_inpaint
111         mask = init_mask_inpaint
112     else:
113         image = None
114         mask = None
115 
116     # Use the EXIF orientation of photos taken by smartphones.
117     if image is not None:
118         image = ImageOps.exif_transpose(image)
119 
120     if selected_scale_tab == 1:
121         assert image, "Can't scale by because no image is selected"
122 
123         width = int(image.width * scale_by)
124         height = int(image.height * scale_by)
125 
126     assert 0. <= denoising_strength <= 1., 'can only work with strength in [0.0, 1.0]'
127 
128     p = StableDiffusionProcessingImg2Img(
129         sd_model=shared.sd_model,
130         outpath_samples=opts.outdir_samples or opts.outdir_img2img_samples,
131         outpath_grids=opts.outdir_grids or opts.outdir_img2img_grids,
132         prompt=prompt,
133         negative_prompt=negative_prompt,
134         styles=prompt_styles,
135         seed=seed,
136         subseed=subseed,
137         subseed_strength=subseed_strength,
138         seed_resize_from_h=seed_resize_from_h,
139         seed_resize_from_w=seed_resize_from_w,
140         seed_enable_extras=seed_enable_extras,
141         sampler_name=sd_samplers.samplers_for_img2img[sampler_index].name,
142         batch_size=batch_size,
143         n_iter=n_iter,
144         steps=steps,
145         cfg_scale=cfg_scale,
146         width=width,
147         height=height,
148         restore_faces=restore_faces,
149         tiling=tiling,
150         init_images=[image],
151         mask=mask,
152         mask_blur=mask_blur,
153         inpainting_fill=inpainting_fill,
154         resize_mode=resize_mode,
155         denoising_strength=denoising_strength,
156         image_cfg_scale=image_cfg_scale,
157         inpaint_full_res=inpaint_full_res,
158         inpaint_full_res_padding=inpaint_full_res_padding,
159         inpainting_mask_invert=inpainting_mask_invert,
160         override_settings=override_settings,
161     )
162 
163     p.scripts = modules.scripts.scripts_img2img
164     p.script_args = args
165 
166     if shared.cmd_opts.enable_console_prompts:
167         print(f"\nimg2img: {prompt}", file=shared.progress_print_out)
168 
169     if mask:
170         p.extra_generation_params["Mask blur"] = mask_blur
171 
172     if is_batch:
173         assert not shared.cmd_opts.hide_ui_dir_config, "Launched with --hide-ui-dir-config, batch img2img disabled"
174 
175         process_batch(p, img2img_batch_input_dir, img2img_batch_output_dir, img2img_batch_inpaint_mask_dir, args)
176 
177         processed = Processed(p, [], p.seed, "")
178     else:
179         processed = modules.scripts.scripts_img2img.run(p, *args)
180         if processed is None:
181             processed = process_images(p)
182 
183     p.close()
184 
185     shared.total_tqdm.clear()
186 
187     generation_info_js = processed.js()
188     if opts.samples_log_stdout:
189         print(generation_info_js)
190 
191     if opts.do_not_show_images:
192         processed.images = []
193 
194     return processed.images, generation_info_js, plaintext_to_html(processed.info), plaintext_to_html(processed.comments)
195
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/modules/img2img.py b/modules/img2img.py
--- a/modules/img2img.py
+++ b/modules/img2img.py
@@ -48,7 +48,8 @@
 
         try:
             img = Image.open(image)
-        except UnidentifiedImageError:
+        except UnidentifiedImageError as e:
+            print(e)
             continue
         # Use the EXIF orientation of photos taken by smartphones.
         img = ImageOps.exif_transpose(img)

{"golden_diff": "diff --git a/modules/img2img.py b/modules/img2img.py\n--- a/modules/img2img.py\n+++ b/modules/img2img.py\n@@ -48,7 +48,8 @@\n \r\n         try:\r\n             img = Image.open(image)\r\n-        except UnidentifiedImageError:\r\n+        except UnidentifiedImageError as e:\r\n+            print(e)\r\n             continue\r\n         # Use the EXIF orientation of photos taken by smartphones.\r\n         img = ImageOps.exif_transpose(img)\n", "issue": "[Feature Request]: img2img batch should ignore non-image files\n### Is there an existing issue for this?\n\n- [X] I have searched the existing issues and checked the recent builds/commits\n\n### What would your feature do ?\n\nI may place some parameter files along the image files in the same folder.\r\nCurrently an exception is throw for non-image files when do \"Image.open()\".\n\n### Proposed workflow\n\n1. Place a txt file along with the png file in folder A\r\n2. Set batch input folder to A\r\n3. Press generate\r\n\n\n### Additional information\n\n_No response_\n", "before_files": [{"content": "import math\r\nimport os\r\nimport sys\r\nimport traceback\r\n\r\nimport numpy as np\r\nfrom PIL import Image, ImageOps, ImageFilter, ImageEnhance, ImageChops, UnidentifiedImageError\r\n\r\nfrom modules import devices, sd_samplers\r\nfrom modules.generation_parameters_copypaste import create_override_settings_dict\r\nfrom modules.processing import Processed, StableDiffusionProcessingImg2Img, process_images\r\nfrom modules.shared import opts, state\r\nimport modules.shared as shared\r\nimport modules.processing as processing\r\nfrom modules.ui import plaintext_to_html\r\nimport modules.images as images\r\nimport modules.scripts\r\n\r\n\r\ndef process_batch(p, input_dir, output_dir, inpaint_mask_dir, args):\r\n    processing.fix_seed(p)\r\n\r\n    images = shared.listfiles(input_dir)\r\n\r\n    is_inpaint_batch = False\r\n    if inpaint_mask_dir:\r\n        inpaint_masks = shared.listfiles(inpaint_mask_dir)\r\n        is_inpaint_batch = len(inpaint_masks) > 0\r\n    if is_inpaint_batch:\r\n        print(f\"\\nInpaint batch is enabled. {len(inpaint_masks)} masks found.\")\r\n\r\n    print(f\"Will process {len(images)} images, creating {p.n_iter * p.batch_size} new images for each.\")\r\n\r\n    save_normally = output_dir == ''\r\n\r\n    p.do_not_save_grid = True\r\n    p.do_not_save_samples = not save_normally\r\n\r\n    state.job_count = len(images) * p.n_iter\r\n\r\n    for i, image in enumerate(images):\r\n        state.job = f\"{i+1} out of {len(images)}\"\r\n        if state.skipped:\r\n            state.skipped = False\r\n\r\n        if state.interrupted:\r\n            break\r\n\r\n        try:\r\n            img = Image.open(image)\r\n        except UnidentifiedImageError:\r\n            continue\r\n        # Use the EXIF orientation of photos taken by smartphones.\r\n        img = ImageOps.exif_transpose(img)\r\n        p.init_images = [img] * p.batch_size\r\n\r\n        if is_inpaint_batch:\r\n            # try to find corresponding mask for an image using simple filename matching\r\n            mask_image_path = os.path.join(inpaint_mask_dir, os.path.basename(image))\r\n            # if not found use first one (\"same mask for all images\" use-case)\r\n            if not mask_image_path in inpaint_masks:\r\n                mask_image_path = inpaint_masks[0]\r\n            mask_image = Image.open(mask_image_path)\r\n            p.image_mask = mask_image\r\n\r\n        proc = modules.scripts.scripts_img2img.run(p, *args)\r\n        if proc is None:\r\n            proc = process_images(p)\r\n\r\n        for n, processed_image in enumerate(proc.images):\r\n            filename = os.path.basename(image)\r\n\r\n            if n > 0:\r\n                left, right = os.path.splitext(filename)\r\n                filename = f\"{left}-{n}{right}\"\r\n\r\n            if not save_normally:\r\n                os.makedirs(output_dir, exist_ok=True)\r\n                if processed_image.mode == 'RGBA':\r\n                    processed_image = processed_image.convert(\"RGB\")\r\n                processed_image.save(os.path.join(output_dir, filename))\r\n\r\n\r\ndef img2img(id_task: str, mode: int, prompt: str, negative_prompt: str, prompt_styles, init_img, sketch, init_img_with_mask, inpaint_color_sketch, inpaint_color_sketch_orig, init_img_inpaint, init_mask_inpaint, steps: int, sampler_index: int, mask_blur: int, mask_alpha: float, inpainting_fill: int, restore_faces: bool, tiling: bool, n_iter: int, batch_size: int, cfg_scale: float, image_cfg_scale: float, denoising_strength: float, seed: int, subseed: int, subseed_strength: float, seed_resize_from_h: int, seed_resize_from_w: int, seed_enable_extras: bool, selected_scale_tab: int, height: int, width: int, scale_by: float, resize_mode: int, inpaint_full_res: bool, inpaint_full_res_padding: int, inpainting_mask_invert: int, img2img_batch_input_dir: str, img2img_batch_output_dir: str, img2img_batch_inpaint_mask_dir: str, override_settings_texts, *args):\r\n    override_settings = create_override_settings_dict(override_settings_texts)\r\n\r\n    is_batch = mode == 5\r\n\r\n    if mode == 0:  # img2img\r\n        image = init_img.convert(\"RGB\")\r\n        mask = None\r\n    elif mode == 1:  # img2img sketch\r\n        image = sketch.convert(\"RGB\")\r\n        mask = None\r\n    elif mode == 2:  # inpaint\r\n        image, mask = init_img_with_mask[\"image\"], init_img_with_mask[\"mask\"]\r\n        alpha_mask = ImageOps.invert(image.split()[-1]).convert('L').point(lambda x: 255 if x > 0 else 0, mode='1')\r\n        mask = ImageChops.lighter(alpha_mask, mask.convert('L')).convert('L')\r\n        image = image.convert(\"RGB\")\r\n    elif mode == 3:  # inpaint sketch\r\n        image = inpaint_color_sketch\r\n        orig = inpaint_color_sketch_orig or inpaint_color_sketch\r\n        pred = np.any(np.array(image) != np.array(orig), axis=-1)\r\n        mask = Image.fromarray(pred.astype(np.uint8) * 255, \"L\")\r\n        mask = ImageEnhance.Brightness(mask).enhance(1 - mask_alpha / 100)\r\n        blur = ImageFilter.GaussianBlur(mask_blur)\r\n        image = Image.composite(image.filter(blur), orig, mask.filter(blur))\r\n        image = image.convert(\"RGB\")\r\n    elif mode == 4:  # inpaint upload mask\r\n        image = init_img_inpaint\r\n        mask = init_mask_inpaint\r\n    else:\r\n        image = None\r\n        mask = None\r\n\r\n    # Use the EXIF orientation of photos taken by smartphones.\r\n    if image is not None:\r\n        image = ImageOps.exif_transpose(image)\r\n\r\n    if selected_scale_tab == 1:\r\n        assert image, \"Can't scale by because no image is selected\"\r\n\r\n        width = int(image.width * scale_by)\r\n        height = int(image.height * scale_by)\r\n\r\n    assert 0. <= denoising_strength <= 1., 'can only work with strength in [0.0, 1.0]'\r\n\r\n    p = StableDiffusionProcessingImg2Img(\r\n        sd_model=shared.sd_model,\r\n        outpath_samples=opts.outdir_samples or opts.outdir_img2img_samples,\r\n        outpath_grids=opts.outdir_grids or opts.outdir_img2img_grids,\r\n        prompt=prompt,\r\n        negative_prompt=negative_prompt,\r\n        styles=prompt_styles,\r\n        seed=seed,\r\n        subseed=subseed,\r\n        subseed_strength=subseed_strength,\r\n        seed_resize_from_h=seed_resize_from_h,\r\n        seed_resize_from_w=seed_resize_from_w,\r\n        seed_enable_extras=seed_enable_extras,\r\n        sampler_name=sd_samplers.samplers_for_img2img[sampler_index].name,\r\n        batch_size=batch_size,\r\n        n_iter=n_iter,\r\n        steps=steps,\r\n        cfg_scale=cfg_scale,\r\n        width=width,\r\n        height=height,\r\n        restore_faces=restore_faces,\r\n        tiling=tiling,\r\n        init_images=[image],\r\n        mask=mask,\r\n        mask_blur=mask_blur,\r\n        inpainting_fill=inpainting_fill,\r\n        resize_mode=resize_mode,\r\n        denoising_strength=denoising_strength,\r\n        image_cfg_scale=image_cfg_scale,\r\n        inpaint_full_res=inpaint_full_res,\r\n        inpaint_full_res_padding=inpaint_full_res_padding,\r\n        inpainting_mask_invert=inpainting_mask_invert,\r\n        override_settings=override_settings,\r\n    )\r\n\r\n    p.scripts = modules.scripts.scripts_img2img\r\n    p.script_args = args\r\n\r\n    if shared.cmd_opts.enable_console_prompts:\r\n        print(f\"\\nimg2img: {prompt}\", file=shared.progress_print_out)\r\n\r\n    if mask:\r\n        p.extra_generation_params[\"Mask blur\"] = mask_blur\r\n\r\n    if is_batch:\r\n        assert not shared.cmd_opts.hide_ui_dir_config, \"Launched with --hide-ui-dir-config, batch img2img disabled\"\r\n\r\n        process_batch(p, img2img_batch_input_dir, img2img_batch_output_dir, img2img_batch_inpaint_mask_dir, args)\r\n\r\n        processed = Processed(p, [], p.seed, \"\")\r\n    else:\r\n        processed = modules.scripts.scripts_img2img.run(p, *args)\r\n        if processed is None:\r\n            processed = process_images(p)\r\n\r\n    p.close()\r\n\r\n    shared.total_tqdm.clear()\r\n\r\n    generation_info_js = processed.js()\r\n    if opts.samples_log_stdout:\r\n        print(generation_info_js)\r\n\r\n    if opts.do_not_show_images:\r\n        processed.images = []\r\n\r\n    return processed.images, generation_info_js, plaintext_to_html(processed.info), plaintext_to_html(processed.comments)\r\n", "path": "modules/img2img.py"}], "after_files": [{"content": "import math\r\nimport os\r\nimport sys\r\nimport traceback\r\n\r\nimport numpy as np\r\nfrom PIL import Image, ImageOps, ImageFilter, ImageEnhance, ImageChops, UnidentifiedImageError\r\n\r\nfrom modules import devices, sd_samplers\r\nfrom modules.generation_parameters_copypaste import create_override_settings_dict\r\nfrom modules.processing import Processed, StableDiffusionProcessingImg2Img, process_images\r\nfrom modules.shared import opts, state\r\nimport modules.shared as shared\r\nimport modules.processing as processing\r\nfrom modules.ui import plaintext_to_html\r\nimport modules.images as images\r\nimport modules.scripts\r\n\r\n\r\ndef process_batch(p, input_dir, output_dir, inpaint_mask_dir, args):\r\n    processing.fix_seed(p)\r\n\r\n    images = shared.listfiles(input_dir)\r\n\r\n    is_inpaint_batch = False\r\n    if inpaint_mask_dir:\r\n        inpaint_masks = shared.listfiles(inpaint_mask_dir)\r\n        is_inpaint_batch = len(inpaint_masks) > 0\r\n    if is_inpaint_batch:\r\n        print(f\"\\nInpaint batch is enabled. {len(inpaint_masks)} masks found.\")\r\n\r\n    print(f\"Will process {len(images)} images, creating {p.n_iter * p.batch_size} new images for each.\")\r\n\r\n    save_normally = output_dir == ''\r\n\r\n    p.do_not_save_grid = True\r\n    p.do_not_save_samples = not save_normally\r\n\r\n    state.job_count = len(images) * p.n_iter\r\n\r\n    for i, image in enumerate(images):\r\n        state.job = f\"{i+1} out of {len(images)}\"\r\n        if state.skipped:\r\n            state.skipped = False\r\n\r\n        if state.interrupted:\r\n            break\r\n\r\n        try:\r\n            img = Image.open(image)\r\n        except UnidentifiedImageError as e:\r\n            print(e)\r\n            continue\r\n        # Use the EXIF orientation of photos taken by smartphones.\r\n        img = ImageOps.exif_transpose(img)\r\n        p.init_images = [img] * p.batch_size\r\n\r\n        if is_inpaint_batch:\r\n            # try to find corresponding mask for an image using simple filename matching\r\n            mask_image_path = os.path.join(inpaint_mask_dir, os.path.basename(image))\r\n            # if not found use first one (\"same mask for all images\" use-case)\r\n            if not mask_image_path in inpaint_masks:\r\n                mask_image_path = inpaint_masks[0]\r\n            mask_image = Image.open(mask_image_path)\r\n            p.image_mask = mask_image\r\n\r\n        proc = modules.scripts.scripts_img2img.run(p, *args)\r\n        if proc is None:\r\n            proc = process_images(p)\r\n\r\n        for n, processed_image in enumerate(proc.images):\r\n            filename = os.path.basename(image)\r\n\r\n            if n > 0:\r\n                left, right = os.path.splitext(filename)\r\n                filename = f\"{left}-{n}{right}\"\r\n\r\n            if not save_normally:\r\n                os.makedirs(output_dir, exist_ok=True)\r\n                if processed_image.mode == 'RGBA':\r\n                    processed_image = processed_image.convert(\"RGB\")\r\n                processed_image.save(os.path.join(output_dir, filename))\r\n\r\n\r\ndef img2img(id_task: str, mode: int, prompt: str, negative_prompt: str, prompt_styles, init_img, sketch, init_img_with_mask, inpaint_color_sketch, inpaint_color_sketch_orig, init_img_inpaint, init_mask_inpaint, steps: int, sampler_index: int, mask_blur: int, mask_alpha: float, inpainting_fill: int, restore_faces: bool, tiling: bool, n_iter: int, batch_size: int, cfg_scale: float, image_cfg_scale: float, denoising_strength: float, seed: int, subseed: int, subseed_strength: float, seed_resize_from_h: int, seed_resize_from_w: int, seed_enable_extras: bool, selected_scale_tab: int, height: int, width: int, scale_by: float, resize_mode: int, inpaint_full_res: bool, inpaint_full_res_padding: int, inpainting_mask_invert: int, img2img_batch_input_dir: str, img2img_batch_output_dir: str, img2img_batch_inpaint_mask_dir: str, override_settings_texts, *args):\r\n    override_settings = create_override_settings_dict(override_settings_texts)\r\n\r\n    is_batch = mode == 5\r\n\r\n    if mode == 0:  # img2img\r\n        image = init_img.convert(\"RGB\")\r\n        mask = None\r\n    elif mode == 1:  # img2img sketch\r\n        image = sketch.convert(\"RGB\")\r\n        mask = None\r\n    elif mode == 2:  # inpaint\r\n        image, mask = init_img_with_mask[\"image\"], init_img_with_mask[\"mask\"]\r\n        alpha_mask = ImageOps.invert(image.split()[-1]).convert('L').point(lambda x: 255 if x > 0 else 0, mode='1')\r\n        mask = ImageChops.lighter(alpha_mask, mask.convert('L')).convert('L')\r\n        image = image.convert(\"RGB\")\r\n    elif mode == 3:  # inpaint sketch\r\n        image = inpaint_color_sketch\r\n        orig = inpaint_color_sketch_orig or inpaint_color_sketch\r\n        pred = np.any(np.array(image) != np.array(orig), axis=-1)\r\n        mask = Image.fromarray(pred.astype(np.uint8) * 255, \"L\")\r\n        mask = ImageEnhance.Brightness(mask).enhance(1 - mask_alpha / 100)\r\n        blur = ImageFilter.GaussianBlur(mask_blur)\r\n        image = Image.composite(image.filter(blur), orig, mask.filter(blur))\r\n        image = image.convert(\"RGB\")\r\n    elif mode == 4:  # inpaint upload mask\r\n        image = init_img_inpaint\r\n        mask = init_mask_inpaint\r\n    else:\r\n        image = None\r\n        mask = None\r\n\r\n    # Use the EXIF orientation of photos taken by smartphones.\r\n    if image is not None:\r\n        image = ImageOps.exif_transpose(image)\r\n\r\n    if selected_scale_tab == 1:\r\n        assert image, \"Can't scale by because no image is selected\"\r\n\r\n        width = int(image.width * scale_by)\r\n        height = int(image.height * scale_by)\r\n\r\n    assert 0. <= denoising_strength <= 1., 'can only work with strength in [0.0, 1.0]'\r\n\r\n    p = StableDiffusionProcessingImg2Img(\r\n        sd_model=shared.sd_model,\r\n        outpath_samples=opts.outdir_samples or opts.outdir_img2img_samples,\r\n        outpath_grids=opts.outdir_grids or opts.outdir_img2img_grids,\r\n        prompt=prompt,\r\n        negative_prompt=negative_prompt,\r\n        styles=prompt_styles,\r\n        seed=seed,\r\n        subseed=subseed,\r\n        subseed_strength=subseed_strength,\r\n        seed_resize_from_h=seed_resize_from_h,\r\n        seed_resize_from_w=seed_resize_from_w,\r\n        seed_enable_extras=seed_enable_extras,\r\n        sampler_name=sd_samplers.samplers_for_img2img[sampler_index].name,\r\n        batch_size=batch_size,\r\n        n_iter=n_iter,\r\n        steps=steps,\r\n        cfg_scale=cfg_scale,\r\n        width=width,\r\n        height=height,\r\n        restore_faces=restore_faces,\r\n        tiling=tiling,\r\n        init_images=[image],\r\n        mask=mask,\r\n        mask_blur=mask_blur,\r\n        inpainting_fill=inpainting_fill,\r\n        resize_mode=resize_mode,\r\n        denoising_strength=denoising_strength,\r\n        image_cfg_scale=image_cfg_scale,\r\n        inpaint_full_res=inpaint_full_res,\r\n        inpaint_full_res_padding=inpaint_full_res_padding,\r\n        inpainting_mask_invert=inpainting_mask_invert,\r\n        override_settings=override_settings,\r\n    )\r\n\r\n    p.scripts = modules.scripts.scripts_img2img\r\n    p.script_args = args\r\n\r\n    if shared.cmd_opts.enable_console_prompts:\r\n        print(f\"\\nimg2img: {prompt}\", file=shared.progress_print_out)\r\n\r\n    if mask:\r\n        p.extra_generation_params[\"Mask blur\"] = mask_blur\r\n\r\n    if is_batch:\r\n        assert not shared.cmd_opts.hide_ui_dir_config, \"Launched with --hide-ui-dir-config, batch img2img disabled\"\r\n\r\n        process_batch(p, img2img_batch_input_dir, img2img_batch_output_dir, img2img_batch_inpaint_mask_dir, args)\r\n\r\n        processed = Processed(p, [], p.seed, \"\")\r\n    else:\r\n        processed = modules.scripts.scripts_img2img.run(p, *args)\r\n        if processed is None:\r\n            processed = process_images(p)\r\n\r\n    p.close()\r\n\r\n    shared.total_tqdm.clear()\r\n\r\n    generation_info_js = processed.js()\r\n    if opts.samples_log_stdout:\r\n        print(generation_info_js)\r\n\r\n    if opts.do_not_show_images:\r\n        processed.images = []\r\n\r\n    return processed.images, generation_info_js, plaintext_to_html(processed.info), plaintext_to_html(processed.comments)\r\n", "path": "modules/img2img.py"}]}