views:

670

answers:

3

I am looking for a solution for a client who has a drawing tablet (an input device that simulates mouse movements using a pen) attached to her computer to directly "draw" on an area on a web page. I will then need the results send to a server side script, PHP in my case.

Essentially, this would be a simple mouse drawing canvas with the specialty that its resolution (i.e. the number of mouse movements it catches per second) needs to be very high, otherwise round lines in the drawing will become "polygonal" when moving the pen / mouse fast. It would also have to have a high level of graphical quality, i.e. antialiase the penstroke. Nothing fancy here but a MS Paint style, 1x1 Pixel stroke won't cut it.

I find this a very interesting thing in general, seeing as Tablet PCs are becoming at least a bit more common. (Not that they get the attention I feel they deserve).

Any suggestions are highly appreciated. I would prefer an Open Source solution, but I am also open to proprietary solutions like ActiveX controls or Java Applets.

Please note that most "canvas" libraries around, and most answers to other questions similar to mine, refer to programmatically drawing onto a canvas. This is not what I am looking for. I am looking for something that records the actual pen or mouse movements of the user drawing on a certain area.

+3  A: 

Hi. there are some applets for this in the oekaki world: Shi painter, Chibipaint or PaintBBS. Here you have php classes for integration.

Drawings produced by these applets can have quite good quality. If you register in oekakicentral.com you can see all the galleries and some drawings have an animation link that shows how was it drawn (it depends on the applet), so you can compare the possibilities of the applets. Some of them are open source.

Edit: See also this made in HTML 5.

nacmartin
+3  A: 

Have a look at <InputDraw/>: a flash component that turns freehand drawing into SVG. Then you could send back the generated SVG to your server.

It's free for non commercial use. According to their site, commercial use price is 29€. It's not open source though.

IMHO it's worth a look.

Alternatively, you implement something based on svg-edit which is open source and uses jQuery (demo). If requires the Google Frame Plugin for IE6+ support though.

EDIT: I just found the svg-freehand-signature project (demo) that captures your handwritten signature and sends it to a server as a SVG using POST. It's distributed as a straight-forward and self-contained zip (works out of the box with Safari and Firefox, you may want to combine it with svgweb that brings SVG support to Internet Explorer).

EDIT: I successfully combined Cesar Oliveira's canvaslol (just look at the source of the page to see how it works) with ExplorerCanvas to have something on IE. You can also have a look at Anne van Kesteren's Paintr experiment.

Gregory Pakosz
+1 for svg-edit...
Stobor
The "turn drawings to SVG" angle is very interesting, and especially svg-freehand-signature looks great and is fast enough. For the purposes of this bounty, I am going to go with nacmartin's oekaki suggestions as the project in question is mainly about painting, and those editors promise a ton of different strokes, textures and the like. Still - great and useful links, thanks!
Pekka
Well... it's your call anyway. Imho Oekaki and Java applets are so 1999... the user experience will never be as smooth as with Javascript or eventually flash. The main advantage of SVG is that you get something meaningful to work with afterwards, not just an image.
Gregory Pakosz
+2  A: 

I doubt you'll get anything higher resolution than the "onmousemove" event gives you, without writing an efficient assembler program on some embedded system custom built for the purpose. You run inside an OS, you play by the OS's rules, which means you're limited by the frequency of the timeslices an OS will give you. (usually about 100 per second, fluxuating depending on load) I've not used a tablet that can overcome the "polygon" problem, and I've used some high end tablets. Photoshop overcomes the problem with cubic interpolation.

That is, unless, you have a very special tablet that will capture many movement events and queue them up to some internal buffer, and send a whole packet of coordinates at a time when it dispatches data to the OS. I've looked at tablet api's though, and they only give one set of coordinates at a time, so if this is going to happen, you'll need custom hardware, and a custom driver, and custom apis that can handle packets of multiple coordinates.

Or you could just use a damned canvas tag, the onmousemove event, event.pageX|pageY some cubic interpolation, the "toDataURI" api of canvas, post the result to your php script, and then just say you did all that other fancy stuff.

onmousemove, in my tests, will give you one event per pixel of movement, limited only by the speed of the event loop in the browser. You'll get sparse data points (polygons) with fast movement and that's as good as it gets without a huge research grant and a hardware designer. Deal.

Breton
Thanks for the background information. I didn't know about how photoshop does it, very interesting. I have found some solutions in the other questions that look promising to me and seem to provide appropriate update frequency to me (I haven't had the time to test them yet with a tablet, though).
Pekka