#python# 来找茬

2019-09-10 18:55:39 浏览数 (1)

来找茬咯!

python源码 [find_difference.py]:

代码语言:javascript复制
# encoding=utf8

from PIL import Image

def get_cut_size(image, is_up_down=True):
   width = image.size[0]
   height = image.size[1]    
    return [(0, 0, width, height / 2), (0, height / 2   (1 if height % 2 else 0), width, height)] 
        if is_up_down 
        else [(0, 0, width / 2, height), (width / 2   (1 if width % 2 else 0), 0, width, height)]
        
def get_cut_image(image, image_size):
   width = image.size[0]
   height = image.size[1]
    return [image.crop(size) for size in image_size]
    
def find_difference(file, up_down_mode=True):
   image = Image.open(file)
   images = get_cut_image(image, get_cut_size(image, up_down_mode))
   images[0].save(file   '.gif', save_all=True,
                  append_images=images, loop=0, duration=400)

if __name__ == '__main__':
   find_difference('cats.png')
   find_difference('cats_and_dogs.png', False)

0 人点赞