diff --git a/layergen.py b/layergen.py index fc2db4e..5f6aa96 100644 --- a/layergen.py +++ b/layergen.py @@ -387,6 +387,11 @@ class mstr_layergen: pick = randrange(0, len(masks)) patchmask = Image.open(masks[pick]) patchmask = patchmask.rotate(randrange(0, 360), expand=True) + + # Make sure patch is within bounds + if patchmask.width > self._imgsize or patchmask.height > self._imgsize: + patchmask.resize((mstr_photores, mstr_photores), Image.Resampling.BILINEAR) + patchpix = patchmask.load() # Pick from possible tags and values for the patches numbers = list(range(1, 16)) diff --git a/photogen.py b/photogen.py index ce2decf..17b6b0f 100644 --- a/photogen.py +++ b/photogen.py @@ -126,6 +126,11 @@ class mstr_photogen: pick = randrange(0, len(masks)) patchmask = Image.open(masks[pick]) patchmask = patchmask.rotate(randrange(0, 360), expand=True) + + # Make sure patch is within bounds + if patchmask.width > self._tile.width or patchmask.height > self._tile.height: + patchmask.resize((mstr_photores, mstr_photores), Image.Resampling.BILINEAR) + patchpix = patchmask.load() # Pick from possible tags and values for the patches