亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術文章
文章詳情頁

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

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

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

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

最終達到如下效果:

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

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

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

調用方法

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(); },

調用下面方法,解開圖片信息

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/

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

標簽: Vue
相關文章:
主站蜘蛛池模板: 久久精品国产亚洲片 | 欧美日韩综合精品一区二区三区 | 中文在线日本免费永久18近 | 国产香蕉视频在线播放 | 国产高清国内精品福利99久久 | 日本高清xxxx免费视频 | 成人精品视频网站 | 亚洲精品乱码久久久久久蜜桃欧美 | 国产精品手机在线亚洲 | 国产裸舞福利在线视频合集 | 一级看片免费视频 | 欧美人成在线观看网站高清 | 久久er国产精品免费观看8 | 路线1路线二线路三国产 | 99久久www免费| 亚洲最大激情中文字幕 | 一区二区精品 | 一极黄色片 | 农村高清性色生活片 | 狠狠色丁香婷婷久久综合考虑 | julia一区二区中文字幕 | 永久免费的啪啪免费的网址 | 免费看午夜高清性色生活片 | 免费看一片 | 欧美日韩午夜精品不卡综合 | 91视频丝瓜| a级毛片视频免费观看 | 欧美日韩亚洲高清不卡一区二区三区 | 青青青在线视频国产 | 国产午夜永久福利视频在线观看 | 久久99国产精品久久欧美 | 国产香蕉98碰碰久久人人 | 女女同性一区二区三区四区 | 国产高清视频免费最新在线 | 亚洲精品不卡在线 | 国产一级一片免费播放视频 | 天天色天天综合 | 日本欧洲95视频 | 手机免费看黄在线高清视频 | 国产小视频在线高清播放 | 欧美日韩精品一区二区 |