国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術(shù)文章
文章詳情頁

vue中使用帶隱藏文本信息的圖片、圖片水印的方法

瀏覽:30日期:2023-01-24 18:26:38

一.帶隱藏文本信息的圖片

通過RGB 分量值的小量變動,不影響對圖片的識別。因此,我們可以在圖片加入文字信息。

最終達(dá)到如下效果:

vue中使用帶隱藏文本信息的圖片、圖片水印的方法

首先,在該組件中加入img用于顯示圖片

<canvas ref='canvas' v-show='0'></canvas><img :src='http://www.cgvv.com.cn/bcjs/imageUrl' v-if='imageUrl'/>

調(diào)用方法

encryptionImg({ width = ’’, height = ’’, content = ’’, }){ let img = this.img const imgRatio = img.naturalWidth / img.naturalHeight; const ctxWidth = width || img.naturalWidth; const ctxHeight = height || ctxWidth / imgRatio; this.canvas.width = ctxWidth; this.canvas.height = ctxHeight; const ctx = this.ctx; ctx.font = ’16px Microsoft Yahei’; ctx.textAlign = ’left’; ctx.textBaseline = ’top’; ctx.fillText(content, 12, ctxHeight/2, ctxWidth);17 const textData = ctx.getImageData(0, 0, ctxWidth, ctxHeight); this.imageUrl = this.mergeData(textData.data, ’R’,ctxWidth,ctxHeight);19 }

把文字和圖片整合成一張圖

mergeData(newData, color, width, height) { let img = this.img this.ctx.drawImage(img, 0, 0, width, height); this.originalData = this.ctx.getImageData(0, 0, width, height); var oData = this.originalData.data; var bit, offset; switch (color) { case ’R’: bit = 0; offset = 3; break; case ’G’: bit = 1; offset = 2; break; case ’B’: bit = 2; offset = 1; break; } for (var i = 0; i < oData.length; i++) { if (i % 4 == bit) { if (newData[i + offset] === 0 && (oData[i] % 2 === 1)) { if (oData[i] === 255) {oData[i]-- } else {oData[i]++ } } else if (newData[i + offset] !== 0 && (oData[i] % 2 === 0)) { if (oData[i] === 255) {oData[i]-- } else {oData[i]++ } } } } this.ctx.putImageData(this.originalData, 0, 0); return this.canvas.toDataURL(); },

調(diào)用下面方法,解開圖片信息

decryptImg(){ var data = this.originalData.data; for(var i = 0; i < data.length; i++){ if(i % 4 == 0){ if(data[i] % 2 == 0){ data[i] = 0; } else { data[i] = 255; } } else if(i % 4 == 3){ continue; } else { data[i] = 0; } } this.ctx.putImageData(this.originalData, 0, 0); this.imageUrl = this.canvas.toDataURL(); },

二.圖片水印

watermark({ content = ’’, container = ’’, width = ’’, height = ’’, position = ’bottom-right’, font = ’16px 微軟雅黑’, fillStyle = ’rgba(255, 255, 255, 1)’, zIndex = 11000, } = {}) { let img = this.img const imgRatio = img.naturalWidth / img.naturalHeight; const ctxWidth = width || img.naturalWidth; const ctxHeight = height || ctxWidth / imgRatio; this.canvas.width = ctxWidth; this.canvas.height = ctxHeight; const ctx = this.ctx; ctx.drawImage(img, 0, 0, ctxWidth, ctxHeight); ctx.shadowColor = ’rgba(0, 0, 0, 0.2)’; ctx.shadowOffsetX = 2; ctx.shadowOffsetY = 2; ctx.shadowBlur = 2; ctx.font = font; ctx.fillStyle = fillStyle; if(position == ’center’) { ctx.textAlign = ’center’; ctx.textBaseline = ’middle’; ctx.fillText(content, ctxWidth / 2, ctxHeight / 2, ctxWidth) }else if(position == ’bottom-right’) { ctx.textAlign = ’right’; ctx.textBaseline = ’alphabetic’; ctx.fillText(content, ctxWidth-12, ctxHeight-12, ctxWidth) } const base64Url = this.canvas.toDataURL(); if(container) { const div = document.createElement(’div’); div.setAttribute(’style’, ` width: ${ctxWidth}px; height: ${ctxHeight}px; z-index: ${zIndex}; pointer-events: none; background-repeat: repeat; background-image: url(’${base64Url}’)`); container.insertBefore(div, null); } this.imageUrl = base64Url }

參考

http://www.alloyteam.com/2016/03/image-steganography/

到此這篇關(guān)于vue中使用帶隱藏文本信息的圖片、圖片水印的文章就介紹到這了,更多相關(guān)vue 隱藏文本信息圖片水印內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: Vue
相關(guān)文章:
主站蜘蛛池模板: 免费观看国产精品 | 欧美日韩在线视频 | 午夜91理论片 | 亚洲成a人一区二区三区 | 久久com| 中文字幕在线视频精品 | 亚洲欧美高清视频 | 日本免费毛片 | 美女个护士一级毛片亚洲 | 亚洲qingse中文久久网 | 一区二区影院 | 亚洲精品人成在线观看 | 国产精品毛片va一区二区三区 | 黄影院 | 亚洲国产成人在线 | 日本黄网站高清色大全 | 国产精品理论片在线观看 | 亚洲欧美日韩精品久久亚洲区色播 | 成人午夜视频一区二区国语 | 日韩欧美亚洲中字幕在线播放 | 经典三级久久久久 | 99www综合久久爱com | 成人性毛片 | 久久免费资源 | 另类视频在线 | 久久草在线视频播放 | 欧美性色黄大片在线观看 | 美女免费黄网站 | 午夜人成 | 高跟丝袜美女一级毛片 | 中文字幕天堂最新版在线网 | 国产成人丝袜网站在线看 | 男人的天堂久久精品激情 | 日本阿v视频在线观看高清 日本波多野结衣视频 | 色噜噜国产精品视频一区二区 | 亚洲精品久久久久影院 | 毛片高清 | 一本久 | 精品国产午夜肉伦伦影院 | 免费一级特黄a | 免费欧美一级片 |