html5 - prevent client from seeing image used in a javascript canvas -
i have path image in server. paths used javascript load image use in canvas, in following way: js script draws image in canvas: hides parts of image(by covering them black layers)
the problem user can read js script image url, , load entirely(without hidden parts)
is there way solve issue can think off?
imagemap.src = 'pathtojpgimage.jpg'; imagemap.onload = function() { // function draws black circles hiding areas of map coverhidenareas(); }
i've got javascript image scrambler can use. scramble function works on image element. careful getting onload loop. can see scramble onload , reset onload avoid looping when setting new value.
function scramble(el){ var v=document.createelement('canvas') var w=v.width=el.width,h=v.height=el.height,c=v.getcontext('2d') c.drawimage(el,0,0) var id=c.getimagedata(0,0,w,h),d=id.data,l=d.length,i=l/4,a=[] for(;--i;)a[i]=i function s(a){ var l=a.length,x=l>>3,y,t,i=0,s=[] if(l<8)return for(;i<l;i+=x)s[i/x]=s(a.slice(i,i+x)) for(i=4;--i;)y=[6,4,7,5,1,3,0,2][i],t=s[i],s[i]=s[y],s[y]=t s=[].concat.apply([],s) return s } var n=c.createimagedata(w,h),d=n.data,a=s(a) for(var i=0;i<l;i++)d[i]=d[(a[i>>2]*4)+(i%4)] c.putimagedata(n,0,0) el.src=c.canvas.todataurl() } function btnscrambleclick() { var srcimage = document.getelementbyid('srcimage'); srcimage.onload = null; scramble(srcimage); } function previewfile() { var srcimage = document.getelementbyid('srcimage'); var file = document.queryselector('input[type=file]').files[0]; var reader = new filereader(); reader.onloadend = function() { srcimage.src = reader.result; } if (file) { reader.readasdataurl(file); } else { srcimage.src = ""; } }; previewfile();
<input type="file" onchange="previewfile()"/> <p> <button id="btnscramble" onclick="btnscrambleclick()">scramble / unscramble</button> </p> <div id="main"> <img id="srcimage" src="" alt="uploaded image" onload="btnscrambleclick()"> </div>
Comments
Post a Comment