python实现微信头像加国旗

喜迎国庆,最近到处都是充满这对祖国对祝福,这里身为码农我也很开心。 并不是为了想放假(手动狗头) WX20190930-152916@2x 代码如下:

# -*- coding: utf8 -*-
import cv2
# 读取头像和国旗图案
img_head = cv2.imread('/Users/cuixiaoyan/biancheng/python/guoqi/img/touxiang.jpeg')
img_flag = cv2.imread('/Users/cuixiaoyan/biancheng/python/guoqi/img/guoqi.png')
# 获取头像和国旗图案宽度
w_head, h_head = img_head.shape[:2]
w_flag, h_flag = img_flag.shape[:2]
# 计算图案缩放比例
scale = w_head / w_flag / 4
# 缩放图案
img_flag = cv2.resize(img_flag, (0, 0), fx=scale, fy=scale)
# 获取缩放后新宽度
w_flag, h_flag = img_flag.shape[:2]
# 按3个通道合并图片
for c in range(0, 3):
    img_head[w_head - w_flag:, h_head - h_flag:, c] = img_flag[:, :, c]
# 保存最终结果 路径可以写为绝对 或者相对
cv2.imwrite('/Users/cuixiaoyan/biancheng/python/guoqi/img/duang.png', img_head)

祝福祖国永远繁荣昌盛。

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×