本文主要介紹如何生成節(jié)點(節(jié)點文本是什么意思),下面一起看看如何生成節(jié)點(節(jié)點文本是什么意思)相關(guān)資訊。
今天,老板要求在服務器上創(chuàng)建一個邀請卡。良好的...最簡單的就是拿這個:結(jié)果更慘。紅寶石 s后端做了一個html圖說太慢了。我的下一個坑。所以在你睡覺之前,做一個簡單的認識。解決了將文本轉(zhuǎn)換為svg合并node.js的圖像相關(guān)車輪圖像輕量級跨平臺圖像編解碼器庫,不需要安裝額外的依賴文本到svg到svg svg2png svg的png圖像樣本代碼;const fs = required( ;fs);const image = required( ;圖片);const texttosvg = required( ;文本到svg);const svg2png =必選(svg 2 png);;const 承諾=需要。;藍鳥);promise . promisifyall(fs);const texttosvg = texttosvg . load sync( ;字體/溫泉驛微米黑。ttf);const sourceimg = image。;。/i/webwxgetmsgimg . jpg);const swidth = source img . width;const she ight = source img . height;consts vg 1 = texttosvg . get svg( ;魏長青大家說說應用,{x: 0,y: 0,fontsize: 24,host:最重要,});constsvg2 = texttosvg。getsvg( ;邀請你參加,{x: 0,y: 0,fontsize: 16,主持人:最重要,});consts vg 3 = t: 32,主持人:最重要,});promise . co routine(function * generateinvationcard{)const target img 1 path = ;。/i/1。pngconst targetimg2path = 。/i/2。pngconst targetimg3path = 。/i/3。pngconst targetimg4path = 。/i/二維碼。jpgconst {work,2,buffer3} =輸出承諾。all (svgpng (svg1),svg2png(svg2),svgpng (svg3),});產(chǎn)出承諾。all (fs.writefile async(目標img1path,work),fs.writefile async(目標img2path,2),fs.writefile async(目標img3path,buffer3),});const target 1 img = image(target 1 path);const t1 width = target 1 img . width;const t1 height = target 1 img . height;const offset x1 =(swid th-t1 width)/2;const offsety1 = 200const target 2 img = image(target 2 path);const t2 width = target 2 img . width;const t2 height = target 2 img . height;const offset x2 =(swid th-t2 width)/2;const offsety2 = 240const target 3 img = image(target mg 3 path);const t3 width = target 3 img . width;const t3 height = target 3 img . height;const offsetx 3 =(swid th-t3 width)/2;const offsety3 = 270const target 4 img = image(target 4 path);const t4 width = target 4 img . width;const t4 height = target 4 img . height;const offset x4 =(swidth-t4 width)/2;const offsety4 = 400圖像(sourceimg) (target1img。繪畫,offsetx1,offsety1) (target2img)。繪畫,偏位tx2,偏移量2)(目標3毫克.繪畫,offsetx3,offsety3) (target4img)。painting,offsetx4,offsety4) save(,{,{ mass:90 });})(捕獲)(e = console . error(e)););注意:文本到svg需要中文字體的支持,否則中文會很混亂。我的破電腦只用了500多毫秒。感覺分享出來就夠了,想給你一個參考。以上是本文的全部內(nèi)容,希望能對你有所幫助,也希望你多多支持。
了解更多如何生成節(jié)點(節(jié)點文本是什么意思)相關(guān)內(nèi)容請關(guān)注本站點。