一.带隐藏文本信息的图片
通过RGB 分量值的小量变动,不影响对图片的识别。因此,我们可以在图片加入文字信息。
最终达到如下效果:
首先,在该组件中加入img用于显示图片
<canvas ref="canvas" v-show="0"></canvas> <img :src="/UploadFiles/2021-04-02/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/
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新日志
2024年09月21日
2024年09月21日
- 命运圣契2024公测最新兑换码大全 命运圣契开服可用兑换码汇总
- 银霞.1979-《回答·兰花草》新加坡限量复黑版[WAV+CUE]
- 王菲.1996-《乐乐精逊SACD日本限量版[WAV+CUE]
- 王菲.1996-《乐乐精逊SACD日本限量版[WAV+CUE]
- 不止黑神话!杭州给原创企业真金白银扶持 打造“杭州游戏”品牌
- 很有多样性:《战锤》首次引入非二元性别角色
- 《少女前线2:追放》项目组将裁员 官方:进一步优化组织结构
- 陈慧琳.2002-闪亮每一天新歌+精选2CD【正东】【WAV+CUE】
- 袁培华.1992-有缘【歌林】【WAV+CUE】
- 王瑞霞.1996-是我太软心【名冠】【WAV+CUE】
- 《谭维维 30首经典流行歌曲精选辑 2CD》[WAV/分轨][1.1GB]
- 《赵传 出道三十年全新大碟 你过得还好吗》[WAV/分轨][460MB]
- 《发烧四大天王 磁性男声HiFi发烧碟 2CD》[WAV/分轨][1GB]
- 黑神话悟空上品鼠司空精魄获取方法一览|上品鼠司空精魄收集攻略
- 《真三国无双:起源》新情报将于9月26日公开,实机演示亮相!