nobodyk Posted July 28, 2010 Share Posted July 28, 2010 I run an image hosting site and it's using a lot of resources. I temporaly disabled the images by using this code: <?php $myImage = imagecreatefromjpeg('ua.jpg'); header("Content-type: image/jpeg"); imagejpeg($myImage); imagedestroy($myImage); ?> I redirected all images to one, but he server still getting high loads. Is there a way to cache this image so it doesn't use many resources? Quote Link to comment https://forums.phpfreaks.com/topic/209134-use-phpgd-to-cache-an-image/ Share on other sites More sharing options...
PFMaBiSmAd Posted July 28, 2010 Share Posted July 28, 2010 Using GD functions to just output an image is a waste of resources. If you are not manipulating the image, just output the correct content type header followed by the image file. See this function - readfile The GD functions create and operate on a uncompressed bitmap image of your original file (jpg, gif, png... are compressed image formats) and require a large amount of memory. Quote Link to comment https://forums.phpfreaks.com/topic/209134-use-phpgd-to-cache-an-image/#findComment-1092244 Share on other sites More sharing options...
lemmin Posted July 28, 2010 Share Posted July 28, 2010 What you are doing is the opposite of caching the image. Any browser will have to download that image every time whether the user has seen it before or not. You shouldn't have to do anything to have the end-user cache an image because it should be done automatically by his/her browser. As long as your images are output in img tags or in css, you can't really do anything else. Quote Link to comment https://forums.phpfreaks.com/topic/209134-use-phpgd-to-cache-an-image/#findComment-1092247 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.