・右边红框部分是服务器传来的图片
・左边红框部分是在浏览器上看到的重新拼接过的:
通过观察,发现服务器传来的jpg图片:
・jpg图片大小 :W760 x H1200px
・图片分割成16个小块(右边跟下边2小条不动),每块面积:W184 x H296px
・横竖位置对调(Z字型→N字型))
・浏览器将横竖位置还原后重绘
如图:
这样,我们可以用python做一个简单的函数,把图片还原:
from PIL import Image
from os import path
def join_image(input_img_path):
bounds = { # 順番: N字型
1: {"crop": (0, 0, 184, 296), "paste": (0, 0)},
2: {"crop": (0, 296, 184, 592), "paste": (184, 0)},
3: {"crop": (0, 592, 184, 888), "paste": (368, 0)},
4: {"crop": (0, 888, 184, 1184), "paste": (552, 0)},
#
5: {"crop": (184, 0, 368, 296), "paste": (0, 296)},
6: {"crop": (184, 296, 368, 592), "paste": (184, 296)},
7: {"crop": (184, 592, 368, 888), "paste": (368, 296)},
8: {"crop": (184, 888, 368, 1184), "paste": (552, 296)},
#
9: {"crop": (368, 0, 552, 296), "paste": (0, 592)},
10: {"crop": (368, 296, 552, 592), "paste": (184, 592)},
11: {"crop": (368, 592, 552, 888), "paste": (368, 592)},
12: {"crop": (368, 888, 552, 1184), "paste": (552, 592)},
#
13: {"crop": (552, 0, 736, 296), "paste": (0, 888)},
14: {"crop": (552, 296, 736, 592), "paste": (184, 888)},
15: {"crop": (552, 592, 736, 888), "paste": (368, 888)},
16: {"crop": (552, 888, 736, 1184), "paste": (552, 888)}
}
old_image = Image.open(input_img_path)
new_img = old_image.copy()
unuse = (1, 6, 11, 16) # (縦横)と関係なく順番が同じ
for i in range(1, 17):
if i in unuse:
continue
new_img.paste(old_image.crop(bounds[i]["crop"]), bounds[i]["paste"])
return new_img
input_img_path = "test.jpg"
new_img = join_image(input_img_path)
# filename.ext -> filename_変換.ext
new_img_path = "_変換".join(path.splitext(input_img_path))
new_img.save(new_img_path, quality=80)
当然,浏览器user agent设置成移动版的设备(如ipad)的话,经常会有惊喜!

