We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
Server-side image generation (Read 5892 times)
Server-side image generation
Oct 25th, 2007, 3:11pm
 
It would be nice to be able to have a way to make size() and all of the other processing graphics functions output to a graphics page, like screen[], instead of opening a display window.  That way you could export JPEGs from an application server-side, and display the resulting image on a web page or other document.  This is a fairly secure way of generating images from data on the server that the image is being generated on.  Good for metrics systems and custom graphics or videos that are made from pre-entered user input or data.

Is there a way to hack this without releasing a new version that is tailored to this?
Re: Server-side image generation
Reply #1 - Oct 25th, 2007, 7:34pm
 
You'd need a PGraphics that isn't displayable (like PDF, but without the side effects).  Easy enough to roll your own, add a tab to your sketch called "MyGraphics2D.java" and paste in this code:

import processing.core.*;
public class MyGraphics2D extends PGraphicsJava2D {
 public MyGraphics2D(int width, int height, PApplet applet) {
   super(width, height, applet);
 }
 public boolean displayable() { return false; }
}

Then use that new renderer in your sketch, for example:

size(640,480,"MyGraphics2D");
background(255);
stroke(0);
line(0,0,width,height);
saveFrame("output.tif");
exit();
Re: Server-side image generation
Reply #2 - Oct 25th, 2007, 8:14pm
 
Thanks.

Is there a good tutorial on how to add a tab?

Quote:
Update:

New File.. = New tab.
Re: Server-side image generation
Reply #3 - Oct 25th, 2007, 9:13pm
 
davbol's method is correct, however it's important to note that if running this code from a server, you'll still need a proper windowing environment (X11), and that even though it's not showing a window, it's relying on gui libraries.

and for anyone curious... separating processing out from the gui/windowing stuff would be a significant undertaking. a better option would be to use a pure-java awt implementation (can't recall the name of the project just now) that would fake a gui without needing the gui libs, so that we could run things server side.
Re: Server-side image generation
Reply #4 - Oct 27th, 2007, 7:14pm
 
hmm, will check into the X11 libraries issue

another question I have is: can you render JoGL/P3D in this way?
Re: Server-side image generation
Reply #5 - Nov 3rd, 2007, 2:51am
 
Ben,

Does this help?

http://javatechniques.com/blog/linux-x11-libraries-for-headless-mode/

-h3
Re: Server-side image generation
Reply #6 - Nov 3rd, 2007, 4:32pm
 
it might, what i was referring to is this:
http://www.eteks.com/pja/en/

it implements all the native stuff from AWT in pure java, which helps enabled the headless thing. i've not looked into X11 specific solutions for it.

using P3D with that sort of model should work fine, using JOGL is very unlikely to work.
Re: Server-side image generation
Reply #7 - Nov 8th, 2007, 2:06am
 
I modified the _Script and added -Djava.awt.headless=true, but with or without this set I got the following error:

Code:

java version "1.5.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_01-b08)
Java HotSpot(TM) Client VM (build 1.5.0_01-b08, mixed mode, sharing)
---> ./_Script

java.awt.HeadlessException
at sun.java2d.HeadlessGraphicsEnvironment.getDefaultScreenDevice(Unknown Source)
at processing.core.PApplet.main(PApplet.java:6888)
at _YearGenerator.main(_YearGenerator.java:83)


This is against the PJA's claim, which states that it is possible >= 1.4.

More discussion about this..

http://forum.java.sun.com/thread.jspa?threadID=444149&start=10&tstart=0

And this note from the PJA developer:
Quote:
Let's try to clarify the (quite complex) situation. Let's say you want to develop an AWT servlet or application able to run on a UNIX machine. Here's the options :
...
2. If your machine has the basic X11 libs installed but no running X11 DISPLAY, you'll be able to create offscreen images using any AWT classes. With Java 1.3 or an earlier version, you can do this if you configure your JVM with java command line options to use PJAToolkit instead of the default Java toolkit. From Java 1.4, you can do this if you set the java.awt.headless System property to true.


And the smack from Sun
http://java.sun.com/developer/technicalArticles/J2SE/Desktop/headless/

h3
Re: Server-side image generation
Reply #8 - Nov 10th, 2007, 1:17am
 
processing simply does not support headless mode. a future version could perhaps be adapted to work with pja, but that's a way off (and a very low priority).
Re: Server-side image generation
Reply #9 - Nov 28th, 2007, 3:22am
 
I posted this on another topic, but if anyone like me is having trouble rendering headless, please check out Xvfb:

# apt-get install xvfb
# Xvfb :2 &
[1] 14401
# export DISPLAY=":2"
# ./runcode

This'll let you not need to be connected to an X server while rendering. You'll still need the X libs on your render machine but you can render stuff on remote servers without it trying to send over each frame.

Page Index Toggle Pages: 1