phpQuestioner Posted August 21, 2007 Share Posted August 21, 2007 How do you cache a PHP GD Image that you are sending a query string to; in order to display the orginal image? Example: <img src="MyGDPhoto.php?photo=mypic.jpg"> The image is not being cached; because it keeps on having to reload. Quote Link to comment https://forums.phpfreaks.com/topic/66068-how-to-cache-a-queried-php-gd-image/ Share on other sites More sharing options...
phpQuestioner Posted August 22, 2007 Author Share Posted August 22, 2007 Does no one know how I would cache a queried php gd library image? Can some one tell me if it can even be done? Quote Link to comment https://forums.phpfreaks.com/topic/66068-how-to-cache-a-queried-php-gd-image/#findComment-330493 Share on other sites More sharing options...
keeB Posted August 22, 2007 Share Posted August 22, 2007 It's a good question. You'd probably have to build your own caching class. Something like the following <?php class Cache { private $time_limit = 10; //minutes function Cache($obj) { $this->save($obj, $time) } function get($obj) { //check to see if $obj is older than 10 mins //somehow do a check to see if it's state has changed in the database (keep a lastUpdated column?) // if it hasn't changed, return the image from a file instead of the database //display //if it has changed, return false (or something) } } ?> # example client code header("Content-type: image/jpeg"); $i = new Image("my.image"); // reference, hasn't been loaded yet c = new Cache($i) if ($data = $c->get()) { print $data; } else { $i->load(); $i->toBrowser(); } That's probably how I would do it. Quote Link to comment https://forums.phpfreaks.com/topic/66068-how-to-cache-a-queried-php-gd-image/#findComment-330571 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.