微信图像添加国旗可以在微信小程序里面搜索国旗头像小程序进行制作。
*** 作方法:
1、首先,打开手机微信进入,点击下方的发现,再选择上方的小程序。
2、然后在小程序的搜索栏里面点击搜索国旗头像LOVE小程序,并点击进入。
3、进入到国旗小程序制作界面,点击上传头像。
4、选择一张需要制作的头像添加进入,并调整合适的大小。
5、最后制作完成保存好,就可以在手机的图库里面找到制作好的国旗头像了。
Adobe photo shop是专业级的,比较难用。还有简单点的软件,美图秀秀、光影魔术手、isee都很不错,自己用足够了!如果兴趣在广泛的可以同时使用“会声会影",把做成小**也很不错。祝你成功,开心快乐!
主要步骤
获取用户头像
合成
一、获取用户头像
制作自定义头像的第一步就是先选择。在海豚趣图的交互设计中,用户有三种选择的方式:微信头像、本地相册和相机拍摄。获取用户头像的产品设计如下图所示:
1、由于微信官方不再支持通过 wxgetUserInfo 接口来获取用户信息,我们必须通过使用 button 组件并将 open-type 指定为 getUserInfo 类型来获取或展示用户信息。
为优化用户体验,使用 wxgetUserInfo 接口直接d出授权框的开发方式将逐步不再支持。从2018年4月30日开始,小程序与小游戏的体验版、开发版调用 wxgetUserInfo 接口,将无法d出授权询问框,默认调用失败。正式版暂不受影响。上图中d出底部菜单的交互方式无法通过 wxshowActionSheet 来实现(因为该接口只能指定字符串文本,不能使用 button, navigator 等组件)。
因此,只能通过自定义 actionSheet 组件来实现以上功能。
mmp-action-sheet 组件
以下是 mmp-action-sheet 组件的代码。
indexwxml
<view hidden="{{!actionShow}}" class="mask {{mask}}" bindtap="actionHide"> <view class="actionSheet animated {{animation}}"><slot></slot>
<button class="close" bindtap="actionHide">{{closeText}}</button>
</view></view>
2、通过 slot 在 action-sheet 中插入自定义的内容,比如 button、navigator 等。
indexwxss
mask{ position: fixed; top: 0; left: 0; width:100%; height: 100%; background: rgba(0, 0, 0, 05); z-index: 999;}actionSheet{ width: 100%; position: absolute; top: 100%; z-index: 1000; overflow: hidden;
}actionSheet button,actionSheet navigator{ color: #000; text-align: center; background: #fff; border-radius: 0; line-height: 35; font-size: 32rpx; border-bottom: 1rpx solid rgb(236, 236, 236); opacity: 1;
}actionSheet button:active,actionSheet navigator:active{ color:#000; background: rgb(236, 236, 236);
}actionSheet button::after,actionSheet navigator::after{ border: none; border-radius: 0;
}actionSheet close{ border-bottom: none; border-bottom: 50rpx solid #fff; border-top: 16rpx solid rgb(236, 236, 236);
}animated { animation-timing-function: ease-out; animation-duration: 02s; animation-fill-mode: both;
}@keyframes fadeInBottom {from{ transform: translate3d(0, 0, 0);
} to { transform: translate3d(0, -100%, 0);
}
}fadeInBottom { animation-name: fadeInBottom;
}@keyframes fadeOutBottom {from{ transform: translate3d(0, -100%, 0);
} to { transform: translate3d(0, 0, 0);
}
}fadeOutBottom { animation-name: fadeOutBottom;
}@keyframes fadeIn {from{ opacity: 0;
} to { opacity: 1;
}
}fadeIn { animation-name: fadeIn;
}@keyframes fadeOut {from{ opacity: 1;
} to { opacity: 0;
}
}fadeOut { animation-name: fadeOut;
}
indexjs
Component({ properties: { actionSheetStatus: { type: Boolean, value: false,observer(newVal) {
if (newVal) {
thissetData({ actionSheetStatus: true, animationMask: 'fadeIn', animationSheet: 'fadeInBottom'
})
} else { thissetData({ actionSheetStatus: false, animationMask: 'fadeOut', animationSheet: 'fadeOutBottom'
})
}
}
}, closeText: { type: String, value: '取消'
}
}, data: { animationMask: 'fadeIn', animationSheet: 'fadeInBottom'
}, methods: {
closeActionSheet() {
thissetData({ animationMask: 'fadeOut', animationSheet: 'fadeOutBottom'
})
setTimeout(() => {
thissetData({actionSheetStatus: false})
}, 300)
}
}
})
组件只有两个参数:
actionSheetStatus 指定组件的初始展示状态,默认为false,表示不显示组件。
closeText 指定关闭按钮的名字,默认为 取消。
indexjson
{ "component": true, "usingComponents": {}}
接下来在页面中调用组件,在组件中插入了3个 button 组件来实现来获取用户头像:
<action-sheet actionSheetStatus="{{actionSheetStatus}}"><button open-type="getUserInfo" bindgetuserinfo="bindGetUserInfo">使用微信头像</button>
<button bindtap="pickPic" data-source-type="album">使用本地相册</button>
<button bindtap="pickPic" data-source-type="camera">拍照</button>
</action-sheet>
以上我们通过自定义组件 mmp-action-sheet 就解决了原生的 actionsheet 无法指定 button,从而无法获取用户微信头像的问题。
该组件我已经发布到 npm 包,需要用到的同学可以通过 npm 安装,也可以在 github 上查看源码和使用文档。
二、模板
有了原图,接下来我们需要选择模板。如果模板数量不多或者模板变化不频繁,我们可以直接把模板放在本地。鉴于我提供的模板比较多,放在本地会增大小程序源码的大小,我把模板上传到了小程序的云存储中,通过云函数来动态获取模板,方便以后模板扩展。
云函数 tpl 的代码如下:
// 云函数入口文件const cloud = require('wx-server-sdk')cloudinit()// 云函数入口函数exportsmain = async (event, context) => { const wxContext = cloudgetWXContext() // 1 获取数据库引用
const db = clouddatabase() const MAX_LIMIT = 100
// 2 构造查询语句
const countResult = await dbcollection('template')count() const total = countResulttotal // 计算需分几次取
const batchTimes = Mathceil(total / 100) const tasks = [] for (let i = 0; i < batchTimes; i++) { const promise = dbcollection('template')skip(i MAX_LIMIT)limit(MAX_LIMIT)get()
taskspush(promise)
} return (await Promiseall(tasks))reduce((acc, cur) => { return {
data: accdataconcat(curdata),
errMsg: accerrMsg,
}
})
}
页面中调用云函数拉取模板:
getTpl() { const self = this// 调用云函数获取模板
wxcloudcallFunction({
name: 'tpl'
})then(res => {
selfsetData({
templates: resresultdata
})
})
}
三、问题
到这里模板的获取逻辑已经没有问题了,但在开发过程中遇到了一个问题。模板的链接我使用的是云文件ID,当有大量并行加载的时候,只有部分能够显示,我看了一下dom节点其实都已经存在了,image的src的地址也都是正确的。
1、微信官方自230开始已经支持在image中使用云文件ID。云文件ID的格式为: cloud://xxxxxx/templates/01png。我猜测可能是对微信云存储并发请求过多导致的(有知道的同学可以告知),因为我试了一下将云文件ID换成正常的>
由此可知,可以想到有三种可行的解决方案:
2、将模板存储到外部OSS,使用>
3、使用 wxgetTempFileURL 用云文件 ID 换取真实链接,也就是>
4、控制图的并行加载数量。我的实践是将并行加载数量控制在20,当用户滚动的时候再发起下一次请求。
1、在微信顶部搜索文字制作,点击文字制作小程序,进入小程序。
2、点击制作,选择模板。
3、进入文字制作小程序后,点击制作按钮,点击一个模板。添加手机或在线然后添加文字。
4、输入自己的文字,最后点击完成点击生成,保存。
讲几张合成一张,可以利用PS软件来完成,具体步骤如下:
第一步:打开PS,如下图
第二步:打开需要处理的(多张)如下图
第三步:新建一张,像素为20002000,如下图
第四步:将三张需要组合的都拖动到20002000px上,如下图
第五步:将三张拼接在一起,如下图
第六步:按住CTRL+E将图层合并,如下图
第七步:保存即可
1打开手机上的编辑软件,将头像和头像框分别导入到软件中;
2将头像框放置在头像上,调整位置;
3点击“合并”按钮,将头像和头像框合并;
4保存,完成合并。
以上就是关于怎么给头像加国旗全部的内容,包括:怎么给头像加国旗、我想自己做图片,用什么软件好、微信小程序头像怎么改等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)