PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, October 11, 2022

[FIXED] How to load dynamic image w/php gd library, w/o saving it on server or having src="script.php"?

 October 11, 2022     gd, image-manipulation, php     No comments   

Issue

I would like to generate a dynamic image from a script, and then have it load to the browser without being persistent on the server.

However, I cannot call this by setting the image's src="script.php", since that would require running the script that just generated the page and its data all over again, just to get the final data that will generate the graph.

Is there a way to do this that is similar to setting image's src="script.php", but which is called from within another script, and just sends the image without saving it? I need access to the data that is used in the generation of the markup, in order to create this dynamic image.

Or, if not, what is the easiest way to destroy the image once the page is loaded? a quick ajax call?

Is there any way to cache certain data for some limited time frame in order for it to be available to some other script?

Any ideas would be greatly appreciated, as I'm having a really hard time finding the right solution to this...

Thanks!


Solution

You can inline the image into a <img> tag if you need to.
Like

<?php
$final_image_data; // Your image data, generated by GD
$base64_data = base64_encode($final_image_data);
echo "<img src=\"data:image/png;base64,{$base64_data}\" ... />";
?>

That should work on all modern browsers, and IE8. Doesn't work well with some email clients tho (Outlook, for one).



Answered By - Atli
Answer Checked By - Clifford M. (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing