几行代码实现微信渐变国旗头像!附在线制作一键工具
然后,给我们需要的图片(
scrName)加上国旗标签。代码如下:
funcAddFlag(avatarPath string, num int)(scrName string, err error) {
paddingX, paddingY := 20, 20//图片边框长度
scrName = fmt.Sprintf("./output/flag_avatar%d.png", num)
flagPath := fmt.Sprintf("./src/flag%d.png", num)
file, err := os.Create(scrName)
if err != nil {
return
}
defer file.Close()
flagFile, err := os.Open(flagPath)
if err != nil {
return
}
defer flagFile.Close()
flagImg, err := png.Decode(flagFile)
if err != nil {
return
}
avatarFile, err := os.Open(avatarPath)
if err != nil {
return
}
defer avatarFile.Close()
avatarImg, err := jpeg.Decode(avatarFile)
if err != nil {
return
}
//resize avatar
newImage := resize.Resize(uint(flagImg.Bounds().Dx()-20), uint(flagImg.Bounds().Dy()-20), avatarImg, resize.Lanczos3)
resultPng := image.NewRGBA(image.Rect(0, 0, flagImg.Bounds().Dx(), flagImg.Bounds().Dy()))
draw.Draw(resultPng, resultPng.Bounds(), newImage, newImage.Bounds().Min.Sub(image.Pt(paddingX, paddingY)), draw.Over)
draw.Draw(resultPng, resultPng.Bounds(), flagImg, flagImg.Bounds().Min, draw.Over)
err = png.Encode(file, resultPng)
if err != nil {
return
}
return
}
本次分享的国庆节日头像有2个版本。
渐变国庆头像
里面共含有6款渐变样式,乍一看区别不大,细看会有惊喜。
国庆头像挂件
里面共含有12款国庆元素挂件,总有一款适合你。
制作方法都非常简单,首先打开工具,上传图片,
选择模板,就可以生成保存了。(点击头像旁边的箭头可以切换其他样式)
有很多款样式可以生成,这边简单列举一部分,大家可以挑选自己喜欢的使用
最后长按我们生成的头像,就可以保存到手机里了。
大家获取到工具链接后,直接授权登录,系统会自动识别你的头像,然后保存就可以设置成自己的新头像啦!是不是非常简单呢~
十一就快来了,大家换个喜庆的头像庆祝祖国诞辰蛮好的!献上我们的祝福,好好学习,努力工作,认真生活,让我们一起为祖国的明天而努力。
大家抓紧时间按照方法去给自己设置渐变头像吧!
关注本公众号并在公众号后台回复“快乐”
阅读原文 关键词
代码
工具
最新评论
推荐文章
作者最新文章
你可能感兴趣的文章
Copyright Disclaimer: The copyright of contents (including texts, images, videos and audios) posted above belong to the User who shared or the third-party website which the User shared from. If you found your copyright have been infringed, please send a DMCA takedown notice to [email protected]. For more detail of the source, please click on the button "Read Original Post" below. For other communications, please send to [email protected].
版权声明:以上内容为用户推荐收藏至CareerEngine平台,其内容(含文字、图片、视频、音频等)及知识版权均属用户或用户转发自的第三方网站,如涉嫌侵权,请通知[email protected]进行信息删除。如需查看信息来源,请点击“查看原文”。如需洽谈其它事宜,请联系[email protected]。
版权声明:以上内容为用户推荐收藏至CareerEngine平台,其内容(含文字、图片、视频、音频等)及知识版权均属用户或用户转发自的第三方网站,如涉嫌侵权,请通知[email protected]进行信息删除。如需查看信息来源,请点击“查看原文”。如需洽谈其它事宜,请联系[email protected]。