gerkintrigg Posted November 29, 2009 Share Posted November 29, 2009 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 More sharing options...
MadTechie Posted November 30, 2009 Share Posted November 30, 2009 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. Link to comment https://forums.phpfreaks.com/topic/183341-saving-a-gd-library-generated-image/#findComment-967786 Share on other sites More sharing options...
gerkintrigg Posted November 30, 2009 Author Share Posted November 30, 2009 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? Link to comment https://forums.phpfreaks.com/topic/183341-saving-a-gd-library-generated-image/#findComment-968146 Share on other sites More sharing options...
MadTechie Posted November 30, 2009 Share Posted November 30, 2009 Look in the tmp folder you created Link to comment https://forums.phpfreaks.com/topic/183341-saving-a-gd-library-generated-image/#findComment-968356 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.