0

Say I have an image blending program written in Python. I want to show the image blending process in a real-time fashion in the frontend while user adjusting the parameters (say several scroll bars), which might require Javascript.

I guess one way to do so is to use libraries mentioned in this similar question: first write a Python class capable of doing the backend job, compile it into JS code and call it from the frontend. Any better ways?

The image manipulation task might be heavier in the future so I write in Python instead of in JS directly.

Community
  • 1
  • 1
clwen
  • 20,004
  • 31
  • 77
  • 94
  • 1
    I would recommend doing this kind of thing client side rather than server side or you will probably have problems when multiple users are simultaneously connected – Joran Beasley Sep 19 '12 at 15:21
  • I agree that write all the task in client side is simpler. But what if there are some ops are heavy so should be better handled in the server side? I suspect JS is not a good fit for image manipulation as well. – clwen Sep 19 '12 at 15:30
  • 1
    js would work fine with many of the jquery tools ... the more expensive the operation the better the choice to use client side as you have to think of 100's of users simultaneously hitting the server with the expensive code ... I would actually recommend html5 canvas or flash for this kind of thing – Joran Beasley Sep 19 '12 at 15:37
  • 1
    If you absolutely have to do it serverside for some reason you will need to just save images in /tmp or something and serve them back to the js via ajax calls .. or always save same name and periodically reload an image tag ... (just make sure you dont reload image at same time you write to image file) – Joran Beasley Sep 19 '12 at 15:38

1 Answers1

1

Depending on the ops you are going to implement, perhaps you could write a parallel implementation of your algorithms using HTML5 Canvas. Then show that in a minimal resolution or provide some way to set up a viewfinder (basically a cropped part of the whole). Once the actual job's done, show the full result.

You might also want to consider using Node.js for something like this. Essentially this would allow you to use pretty much the same code for both backend and frontend reducing duplication of the algorithms.

You could also try to rethink the way you perform the manipulation. Aviary encourages the users to perform one operation at a time. In addition they provide undo (easy to implement). This kind of scheme would work really well with Canvas.

Juho Vepsäläinen
  • 26,573
  • 12
  • 79
  • 105