2

I have a python script that can output a plot using matplotlib and command line inputs.

What i'm doing right now is making the script print the location/filename of the generated plot image and then when PHP sees it, it outputs an img tag to display it.

The python script deletes images that are older than 20 minutes when it runs. It seems like too much of a workaround, and i'm wondering if there's a better solution.

1 Answer 1

2

You could modify your python script so it outputs an image (image/jpeg) instead of saving it to a file. Then use the tag as normal, but pointing directly to the python script. Your php wouldn't call the python script at all, It would just include it as the src of the image.

Sign up to request clarification or add additional context in comments.

4 Comments

That sounds like something I'm trying to do. What's a good way to feed inputs to the python script like that? I don't have a web framework installed.
You'd have to pass the data in the url, probably as a query string. I'm mostly familiar with mod_python, but there are ways to get at the query string with out using a framework.
As far as I know, without mod_python, when the browser read the python script file, it reads in plaintext and python never gets executed.
You can run python as cgi, but I won't be able to help much there. If you put you python script in a .cgi file, that is usually already setup to be handled correctly. You just have to have #!/your/path/to/python on the first line. Look into the cgitb library documentation on the python site.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.