Use a php script to create an image from data in the Drupal database and include the resulting image in a drupal node?
Hi everyone,
I Just started using Drupal and I am trying to drupalize my existing site. One of the things that I do is use a form to input data into a database then use this data to generate an image. I wrote the script in PHP and use the imagepng() function to print the image. I have figured out how to input the data with drupal and how to access it in the drupal database with php. As long as I have the php file outside my drupal directory it works fine and I see my graph. When I try to include the php code on a drupal page (create content -> page) I get an error. It seems to be a result of the header('Content-type: image/png'); code. When I remove this code I get an image that is gibberish. Is there a special way to make this work in Drupal? do I need to change the "header('Content-type: image/png');" line in my code to something else?
Thanks for the help...
andy

After reading through this
After reading through this three times, I'm starting to suspect you need to look at
http://api.drupal.org/api/function/drupal_set_header
Either that or remember to exit() once you've sent out the image - or return() it. Pasting raw code into a drupal theme without one of those methods will result in binary+HTML mixed up together.
Or do something else, like make the image as a file then redirect to it
Or explain better with some code - this vague description lacks a lot of context.
.dan.
if you are asking a question you think should be documented, please provide a link to the handbook where you think the answer should be found.
| http://www.coders.co.nz/ |
Are you trying to produce an image in a page?
Do you want gold_prices.png to appear in page gold_prices.php? gold_prices.png is a separate HTTP request and is serviced by a separate program in your Web site. When you request gold_prices.php, the browser sees a link to gold_prices.png and makes a separate request. Your .htaccess file might translate gold_prices.png to png.php?i=gold_prices.png then png.php delivers the image setting the right headers in the process.
petermoulding.com/web_architect
Sorry for the vague post...THANKS for wading through it!!!
Dman, Thank you for your help. the drupal_set_header function worked perfectly and fixed my problem. Sorry for the vagueness - I am pretty new to this world of drupal and coding in general so I wasn't sure what info folks needed to help me out. Anyway I really appreciate your help.
andy