Click here to Skip to main content
14,922,433 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hi, anyone knows how to split an image into pieces, using javascript? I need to encrypt and decrypt that picture into pieces so that hacker will have a problem getting the information,

is there any way to split the image by default to uneven shape? like a jig-saw puzzle form, due to security reasons, as I doing a project on that. Example: a random image, split into many parts via code, and the size must be uneven, like bigger square and smaller square, so that it will be harder for hacker to put back the pieces as one.,r:22,s:40&tx=155&ty=94

an example, but the squares are of different size, larger/smaller, (have to do this by coding) do you know to do?


an example, but the squares are of different size, larger/smaller, (have to do this by coding) do you know to do?

Sergey Alexandrovich Kryukov 13-Mar-12 23:59pm
Interesting idea but bad from the security standpoint. Please see my answer.

1 solution

Bad idea. If you need real security, you cannot use JavaScript as it is totally placed on the client side, so it can be easily read and analyzed off-line. After that, one could design and implement an automated work-around solution based on the same data available to your script. In other words, the rough idea is that: looking at your script fully available to the client, one can create an anti-script for it and mimic a human operator to crack your "protection" against a robot.

Therefore, the right solution should be based on server-side code. Besides, in this case, graphic manipulations is way easier to implement and debug, because this is .NET. You can develop and debug the main engine using a desktop application, which is way faster and easier, and then move it to your Web application.

Your .NET solution on the server-side needs only one graphics library to accomplish this task: System.Drawing; please see:[^].

Joel Tan Wei Shan 14-Mar-12 2:36am
I am currently doing a project , whereby, I have to do captcha, where instead of words, we have to encrypt the image into uneven proportion, so that the user can decrypt it back to the original image,

works like a captcha just that its picture form instead, are you able to help me please?
Thank you; this is how I understood it in first place. Interesting part of project and the idea, by the way, but JavaScript is not acceptable.

Now, what help do you expect? I think I gave you the basic idea. It might need hours to design it all, which I hardly would be able to afford. The project looks interesting my may require really good amount of work, even on .NET. Could you focus on some particular concerns?
Joel Tan Wei Shan 14-Mar-12 6:02am
Lets say, one picture, it split into 9 different blocks like

One block of it has to split into 3 different layers of pixel, so if one layer is missing the image will not be as clear as the original as 1 layer of pixel is gone,

Do you know how to do the pixel part?
Sergey Alexandrovich Kryukov 14-Mar-12 12:37pm
Yes, you can use System.Drawing.Bitmap and System.Drawing.Bitmap.LockBits, and System.Runtime.InteropServices.Marshal;
see a code sample here:


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900