enhance outcropping with ability to direct contents of new regions

- When outcropping an image you can now add a `--new_prompt` option, to specify
  a new prompt to be used instead of the original one used to generate the image.

- Similarly you can provide a new seed using `--seed` (or `-S`). A seed of zero
  will pick one randomly.

- This PR also fixes the crash that happened when trying to outcrop an image
  that does not contain InvokeAI metadata.
This commit is contained in:
Lincoln Stein
2022-11-08 17:27:42 +00:00
parent 48aa6416dc
commit 8aa94d5774
5 changed files with 48 additions and 14 deletions

View File

@ -561,18 +561,22 @@ class Generate:
):
# retrieve the seed from the image;
seed = None
image_metadata = None
prompt = None
args = metadata_from_png(image_path)
seed = args.seed
prompt = args.prompt or ''
if seed == 0:
seed = random.randrange(0, np.iinfo(np.uint32).max)
opt.seed = seed
print(f'>> generated new seed {seed} and prompt "{prompt}" for {image_path}')
if opt.seed is not None:
seed = opt.seed
elif args.seed >= 0:
seed = args.seed
else:
print(f'>> retrieved seed {seed} and prompt "{prompt}" from {image_path}')
seed = random.randrange(0, np.iinfo(np.uint32).max)
if opt.prompt is not None:
prompt = opt.prompt
else:
prompt = args.prompt
print(f'>> using seed {seed} and prompt "{prompt}" for {image_path}')
# try to reuse the same filename prefix as the original file.
# we take everything up to the first period
@ -619,6 +623,10 @@ class Generate:
extend_instructions[direction]=int(pixels)
except ValueError:
print(f'** invalid extension instruction. Use <directions> <pixels>..., as in "top 64 left 128 right 64 bottom 64"')
opt.seed = seed
opt.prompt = prompt
if len(extend_instructions)>0:
restorer = Outcrop(image,self,)
return restorer.process (