Browse Source

WIP: change tile formats, add border if necessary

Baptiste Jonglez 6 years ago
parent
commit
d73b28b01a
1 changed files with 8 additions and 4 deletions
  1. 8 4
      panorama/gen_tiles.py

+ 8 - 4
panorama/gen_tiles.py

@@ -32,10 +32,14 @@ def gen_tiles(image, output_path, min_scale=0, max_scale=8, crop_x=256, crop_y=2
                 geom = (x, y, min(im.size[0], x + crop_x),
                         min(im.size[1], y + crop_y))
                 dest = os.path.join(output_path,
-                                    "{:03}-{:03}-{:03}.jpg".format(scale,
-                                                                   x // crop_x,
-                                                                   y // crop_y))
-                im.crop(geom).save(dest)
+                                    "{}-{}-{}.jpg".format(-scale,
+                                                          x // crop_x,
+                                                          y // crop_y))
+                tile = im.crop(geom)
+                if x + crop_x > im.size[0] or y + crop_y > im.size[1]:
+                    # The tile is smaller than 256x256, so fill the rest with black
+                    tile = im.transform((crop_x, crop_y), PIL.Image.AFFINE, (1, 0, x, 0, 1, y))
+                tile.save(dest)
 
 
 if __name__ == '__main__':