Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 533671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:31:57+00:00 2026-05-13T09:31:57+00:00

The way I see most people use Processing is for drawing an image directly

  • 0

The way I see most people use Processing is for drawing an image directly onto a screen or webpage on the client side.

How would one use Processing to create an image without a visual canvas, then save this image to a file?

Here are the specific steps I’m interested in:

  1. Someone visits a webpage, which causes the Processing program to start running
  2. The Processing program would work behind the scenes to create an image, then save it to a known filename
  3. The webpage would load the known filename (which only exists after the Processing program is run – so, how can the webpage know to load the image when it’s finished?)

I’m assuming that the Processing program is running on a server (which is contrary to how Processing usually works), and the file will be stored on the server. I’m also assuming some code in the Processing program to throttle the number of files that are created – for example, it won’t create a new image if an existing image was created within 5 minutes.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T09:31:58+00:00Added an answer on May 13, 2026 at 9:31 am

    I’ve done this, using Processing in a Servlet to render images on the fly.
    A problem I found is that Processing isn’t thread-safe, so I had to create multiple Processing instances and share them in a queue.

    Here’s a servlet which renders Mandelbrot fractals, to be used by Google Maps as an overlay:

    import java.awt.image.BufferedImage;
    import java.io.IOException;
    import java.util.concurrent.LinkedBlockingQueue;
    
    import javax.imageio.ImageIO;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import processing.core.PApplet;
    
    public class Tile extends HttpServlet {
        private static final long serialVersionUID = 1L;
        private static LinkedBlockingQueue<PApplet> pQueue = new LinkedBlockingQueue<PApplet>();
    
        private PApplet createPApplet() {
            PApplet p = new PApplet();
            p.init();
            p.size(256, 256);
            p.noLoop();
            p.textFont(p.createFont("Monospace", 8, true));
            p.stroke(0x22FFFFFF);
            p.colorMode(PApplet.HSB, 256, 1, 1);
            return p;
        }
    
        protected void doGet(HttpServletRequest request,
                HttpServletResponse response) throws ServletException, IOException {
            PApplet p;
    
            if (pQueue.size() == 0) {
                p = createPApplet();
            } else {
                try {
                    p = pQueue.take();
                } catch (InterruptedException e) {
                    p = createPApplet();
                }
            }
    
            int zoom = Integer.parseInt(request.getParameter("z"));
            int tileX = Integer.parseInt(request.getParameter("x"));
            int tileY = Integer.parseInt(request.getParameter("y"));
            int tiles = 1 << zoom;
    
            p.loadPixels();
    
            final int N = 256;
            //final double inverse_N = 2.0 / 256;
            final double inverse_N = 2.0 / tiles / 256;
            int y = -1;
    
            while ((++y) < N) {
                double Civ = (double) (y + tileY * 256) * inverse_N - 1.0;
                for (int x = 0; x < N; x++) {
                    double Crv = (double) (x + tileX * 256) * inverse_N - 1.5;
    
                    double Zrv = Crv;
                    double Ziv = Civ;
    
                    double Trv = Crv * Crv;
                    double Tiv = Civ * Civ;
    
                    int i = 256;
                    do {
                        Ziv = (Zrv * Ziv) + (Zrv * Ziv) + Civ;
                        Zrv = Trv - Tiv + Crv;
    
                        Trv = Zrv * Zrv;
                        Tiv = Ziv * Ziv;
                    } while (((Trv + Tiv) <= 4.0) && (--i > 0));
    
                    if (i == 0) {
                        p.pixels[x + y * N] = 0x00000000;
                    } else {
                        p.pixels[x + y * N] = p.color(256 - i,1,1);
                    }
                } // end foreach column
            }
            p.updatePixels();
    
            // render info
            p.fill(0x22000000);
            p.text("X: " + tileX + "\nY: " + tileY + "\nZ: " + zoom, 1, 13);
            p.fill(0x22FFFFFF);
            p.text("X: " + tileX + "\nY: " + tileY + "\nZ: " + zoom, 0, 12);
    
            p.line(0, 0, 0, 2);
            p.line(0, 0, 2, 0);
            p.line(255, 255, 255, 253);
            p.line(255, 255, 253, 255);
    
            // done
            p.loadPixels();
            BufferedImage img = new BufferedImage(256, 256,
                    BufferedImage.TYPE_INT_ARGB);
            img.setRGB(0, 0, 256, 256, p.pixels, 0, 256);
            p.draw();
    
            response.setHeader("Content-Type", "image/png");
            ImageIO.write(img, "PNG", response.getOutputStream());
    
            try {
                pQueue.put(p);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to test if a collection is already initialized? try-catch only?
I'm trying to build a Chrome browser extension, that should enhance the way the
I would like to remove/delete a migration file. How would I go about doing
I would like to get a sum from a column, with and without a
I am using a 3rd-party rotator object, which is providing a smooth, random rotation
I have several USB mass storage flash drives connected to a Ubuntu Linux computer
I am attempting to pull some information from my tnsnames file using regex. I
I'm in the process of porting some code from Linux to Mac OS X.
I am writing a query to fetch results for all the values in a
I want to have generalised email templates. Currently I have multiple email templates with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.