diff options
Diffstat (limited to 'modules/images.py')
-rw-r--r-- | modules/images.py | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/modules/images.py b/modules/images.py index b05276c3..4b9667d2 100644 --- a/modules/images.py +++ b/modules/images.py @@ -39,23 +39,26 @@ def split_grid(image, tile_w=512, tile_h=512, overlap=64): w = image.width
h = image.height
- now = tile_w - overlap # non-overlap width
- noh = tile_h - overlap
+ non_overlap_width = tile_w - overlap
+ non_overlap_height = tile_h - overlap
- cols = math.ceil((w - overlap) / now)
- rows = math.ceil((h - overlap) / noh)
+ cols = math.ceil((w - overlap) / non_overlap_width)
+ rows = math.ceil((h - overlap) / non_overlap_height)
+
+ dx = (w - tile_w) // (cols-1) if cols > 1 else 0
+ dy = (h - tile_h) // (rows-1) if rows > 1 else 0
grid = Grid([], tile_w, tile_h, w, h, overlap)
for row in range(rows):
row_images = []
- y = row * noh
+ y = row * dy
if y + tile_h >= h:
y = h - tile_h
for col in range(cols):
- x = col * now
+ x = col * dx
if x+tile_w >= w:
x = w - tile_w
|