需求场景(后端生成图片):
应用在几百张图片中随机选取一张图片作为模板,在图片上绘制一些文字,并生成一张图片,传入CDN中,返回用户CDN的图片地址。
优点:不用判断缓存,速度也最快
缺点:应用占用内存大
优点:内存占用小
缺点:写不好,容易内存泄露,读文件导致速度变慢
目前采用了方案1,使用了node-canvas
各位有没有更好的建议,或者方案?
巴扎黑2017-04-17 16:10:48
For scalability considerations, there may be more pictures in the future, or even unlimited pictures. If they are all stored in the server memory, it will definitely not be suitable; if your service is deployed on Alibaba Cloud, buy oss and use the intranet. When you want to use pictures, get them from OSS and store them back in OSS. If they are not on Alibaba Cloud, you can also buy the corresponding cloud storage on other cloud services. Be careful not to purchase cloud services separately, which will require you to go outside the network. Get the picture. If it is your own server, store it in a database, such as mongo. The above storage is all binary of the stored files. In fact, there is no reading of files or memory leaks. Just write the code well.