from PIL import Image
import sys
def cut_image(image):
width, height = image.size
item_width = int(width/4)
box_list = []
count = 0
for j in range(0,4):
for i in range(0,4):
count += 1
box = (i*item_width, j*item_width, (i+1)*item_width, (j+1)*item_width)
box_list.append(box)
print(count)
image_list = [image.crop(box) for box in box_list]
return image_list
def save_images(image_list):
index = 1
for image in image_list:
image.save(r'G:\data4\wangpeng\code1\testresult\crop' + str(index) + '.jpg')
index += 1
if __name__ == '__main__':
file_path = "001.jpg"
image = Image.open(r'G:\data4\wangpeng\code1\test.jpg')
image_list = cut_image(image)
save_images(image_list)