# rows = 0 # cols = 0 for name in tile_names: match = pattern.match(name) ifmatch: r = int(match.group(1)) c = int(match.group(2)) # rows = max(rows, r) # cols = max(cols, c)
# 创建新图 result = Image.new(mode, (img_width, img_height))
# 按序拼接 for index, tile_name inenumerate(tile_names):
match = pattern.match(tile_name) ifmatch: r = int(match.group(1)) c = int(match.group(2)) # 打开切片图像 tile = Image.open(folder+tile_name)
# 拼接 result.paste(tile, (c * tile_width, r * tile_height))
# 保存结果图片 result.save(save_path) print('图像拼接完成!')
或者在使用PIL库读取时,可以直接设置无读取上限
Image.MAX_IMAGE_PIXELS = None # or some other big number