最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How can I manipulate an image using Javascript? - Stack Overflow

programmeradmin0浏览0评论

I have stored an image in a scrambled type of form on the server, which I then display to the user. I would like to use Javascript to dynamically descramble the image on the client side.

Are there ways to do this? I think I need some way to manipulate the image as a binary object to descramble it.

I have stored an image in a scrambled type of form on the server, which I then display to the user. I would like to use Javascript to dynamically descramble the image on the client side.

Are there ways to do this? I think I need some way to manipulate the image as a binary object to descramble it.

Share Improve this question asked Feb 17, 2011 at 13:57 foobarfuzzbizzfoobarfuzzbizz 58.7k57 gold badges147 silver badges198 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 3

You could base64 scramble and descramble it with JavaScript and then get the resulting base64 and insert it into an img tag in your html:

<img alt="Embedded Image" 
   src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIA..." />

However your scrambling algorithm is still available to the user - as much as you hide it or minify it, an expert JS programmer can understand what's happening no matter what.

You could use a canvas.

var can = document.getElementById('canvas');
var ctx = can.getContext('2d');

load an image and draw it in the canvas :

var img = new Image();
img.onload = function(){
    can.width = img.width;
    can.height = img.height;
    ctx.drawImage(img, 0, 0, img.width, img.height);
}
img.src = 'toto.jpg';

and then, you can use methods of the context to manipulate the image :

https://developer.mozilla/en/canvas_tutorial

You could copy the pixel data into canvas and manipulate it there. There's a solid answer available here: Get image data in JavaScript?

发布评论

评论列表(0)

  1. 暂无评论