前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >#python# 来找茬

#python# 来找茬

作者头像
滚神大人
发布2019-09-10 18:55:39
4290
发布2019-09-10 18:55:39
举报
文章被收录于专栏:趣Python趣Python

来找茬咯!

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)
本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2017-12-12,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 趣Python 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档