views:

569

answers:

10

Is it possible to dynamically create and modify images on a per pixel level in JavaScript (on client side)? Or has this to be done with server based languaged, such as PHP?

My use case is as follows:

  • The user opens webpage and loads locally stored image
  • A preview of the image is displayed
  • The user can modify the image with a set of sliders (pixel level operations)
  • In the end he can download the image to his local HDD

When searching in the web I just found posts about using IE's filtering method, but didn't find anything about image editing functions in JavaScript.

+1  A: 

This has to be done on the server side. One thing you might look at doing is allowing all the editing to go on client side, and then in the end POST the final image (via AJAX) to the server to allow it to return it to you as the correct MIME type, and correctly packed.

Sargun Dhillon
+4  A: 

Some browsers support the canvas: http://developer.mozilla.org/En/Drawing_Graphics_with_Canvas

aaronjensen
A: 

You can imagine a set of JS tools that will allow the user to define what kind of transformation he wants to do, but the final work of transformation MUST be done on a server side. JS on the client side is unable to create a file, for security reason.

gizmo
A: 

Is possible to do file editing on the client side inside a Java applet. You will need to signed applet.

Andrei Savu
A: 

Try Allicorn's Image Retargetter - it sounds like that's what you're looking for.

PaulF
A: 

Local image manipulation in JavaScript should be possible - have a look at Defender of the Favicon. ;-) The question is how to get the original image from the file system into your page (I don't know of any other way than doing a HTTP upload to the server first).

Arno
+1  A: 

You may want to check out Processing.js. John Resig of jQuery fame wrote it. It supports pixel processing, unfortunately only Firefox 3 can handle it sufficiently.

Jataro
+1  A: 

Also look at data URIs (though IE versions below 8 don't support them, unfortunately!)

Marijn
+1  A: 

Thanks for all the comments. To summarize, there seem to be solutions for some browsers (e.g. Firefox). However, a solution for all browsers seems to require a server side implementation.

Fabian
A: 

Google Gears has a Blob object which is intended to handle binary data.

pcorcoran