Skip to content

Commit

Permalink
Merge pull request #8175 from vladmandic/image_size
Browse files Browse the repository at this point in the history
adds checks for resulting image size to avoid memory issues
  • Loading branch information
AUTOMATIC1111 authored Mar 11, 2023
2 parents 76bc721 + a47c182 commit d3dd6cc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions modules/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ def list_samplers():
"export_for_4chan": OptionInfo(True, "If the saved image file size is above the limit, or its either width or height are above the limit, save a downscaled copy as JPG"),
"img_downscale_threshold": OptionInfo(4.0, "File size limit for the above option, MB", gr.Number),
"target_side_length": OptionInfo(4000, "Width/height limit for the above option, in pixels", gr.Number),
"img_max_size_mp": OptionInfo(200, "Maximum image size, in megapixels", gr.Number),

"use_original_name_batch": OptionInfo(True, "Use original name for output filename during batch process in extras tab"),
"use_upscaler_name_as_suffix": OptionInfo(False, "Use upscaler name as filename suffix in the extras tab"),
Expand Down
5 changes: 5 additions & 0 deletions scripts/xyz_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,11 @@ def process_axis(opt, vals):
z_opt = self.current_axis_options[z_type]
zs = process_axis(z_opt, z_values)

# this could be moved to common code, but unlikely to be ever triggered anywhere else
Image.MAX_IMAGE_PIXELS = opts.img_max_size_mp * 1.1 # allow 10% overhead for margins and legend
grid_mp = round(len(xs) * len(ys) * len(zs) * p.width * p.height / 1000000)
assert grid_mp < opts.img_max_size_mp, f'Error: Resulting grid would be too large ({grid_mp} MPixels) (max configured size is {opts.img_max_size_mp} MPixels)'

def fix_axis_seeds(axis_opt, axis_list):
if axis_opt.label in ['Seed', 'Var. seed']:
return [int(random.randrange(4294967294)) if val is None or val == '' or val == -1 else val for val in axis_list]
Expand Down

0 comments on commit d3dd6cc

Please sign in to comment.