del*_*aye 0 python crop imagemagick imagemagick-convert wand
我试图在 python 中平铺一个 JPG 图像。通常我使用 imageMagick .. 所以我看到比魔杖似乎做这项工作......
但我不会翻译
convert -crop 256x256 +repage big_image.jpg tiles_%d.jpg
Run Code Online (Sandbox Code Playgroud)
有人可以帮助我吗?
Python 的魔杖库提供了一种独特的裁剪选择。使用wand.image.Image[left:right, top:bottom]可以对新的虚拟像素图像进行子切片。
from wand.image import Image
with Image(filename="big_image.jpg") as img:
i = 0
for h in range(0, img.height, 256):
for w in range(0, img.width, 256):
w_end = w + 256
h_end = h + 256
with img[w:w_end, h:h_end] as chunk:
chunk.save(filename='tiles_{0}.jpg'.format(i))
i += 1
Run Code Online (Sandbox Code Playgroud)
以上将生成许多与以下+repage选项匹配的平铺图像:
convert -crop 256x256 +repage big_image.jpg tiles_%d.jpg
Run Code Online (Sandbox Code Playgroud)