Jump to content

Recommended Posts

Hi all.

 

I've found a great script to generate pie charts as images, but now I want to save the image to import into something else. I can do it fine from the browser, but want to save it automatically via the script.

 

In the script, I reference to it like this:

<img src="includes/pie_charts/print.php?data=15*35*25*25&label=eggs*carrots*Milk*Bread" />

An include file does the rest for me...

Do I need to hack the source or can I write a function to handle it from the reference?

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/183341-saving-a-gd-library-generated-image/
Share on other sites

in print.php your see a line like this

imagejpeg($im);

add this line above it (note you may need to change $im to whatever the variable name is

if(!empty($_GET['file'])) imagejpeg($im, dirname(__FILE__)."/tmp/".basename($_GET['file']).".jpeg");

Now in the pie_charts folder create a folder called tmp and give it write privileges.

 

now this

<img src="includes/pie_charts/print.php?data=15*35*25*25&label=eggs*carrots*Milk*Bread&file=test" />

will display the image as normal but will also create test.jpg in the tmp folder,

 

without seeing the code that about the best i can think of.

in the print.php i now have this:

function OutputImage($img) 
{
header('Content-type: image/jpg');
if(!empty($_GET['file'])) imagejpeg($img, dirname(__FILE__)."/tmp/".basename($_GET['file']).".jpeg");
ImageJPEG($img,NULL,100);
}

 

and in the file that references to it:

<img src="includes/pie_charts/print.php?data=1*2*3*94&label=a*b*c*d&file=test" />

 

It displays fine... I'm not sure whether the image is being created though. how will I know?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.