Jump to content

use php/gd to cache an image


nobodyk

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.