Is it possible to cache images generated by GD? I have a website that generates thumbnails by cropping out a section designated by the user, and there are a ton of these thumbnails. In order to save bandwidth I wanted to cache the images so everyimte someone visits the page the thumbnail image dont have to be re-generated. Any help is appreciated...have you tried to cache the image with some headers?aaaand...i just did and it worked. hah.cool, what did you end up with?header("Expires: ". gmdate("D, d M Y H:i:s", time()+432000) ." GMT");
header("Content-Type: image/jpeg");
basically it stays in the cache for 5 days.
i should probably do it for longer, just because the url specified will always make the same thumbnail no matter what.Is the whole script done nate? I'd love to see it..well, its a module in a big CMS i made. the module cant run stand alone
the thumbnail thing is from a gallery module for my CMS, the user selects an image and then a new window opens up with the image in it and a little box that you can drag around. wherever you put the box is where the thumbnail will be. so you select where you want it and it stores it in a database.
although if all you want is the thumbnail generation:
<?php
$dir = "gallery/";
$specs = (isset($_GET['s']))?$_GET['s']:NULL;
if ($specs) {
$specs = explode(",", $specs);
$loc = $dir . $specs[2] ."/". $specs[3];
if (is_file($loc)) {
$image_type = getimagesize($loc);
$image_type = $image_type[2];
switch ($image_type) {
case 1: $src_img = imagecreatefromgif ($loc); break;
case 2: $src_img = imagecreatefromjpeg($loc); break;
case 3: $src_img = imagecreatefrompng ($loc); break;
}
if ($src_img) {
header("Expires: ". gmdate("D, d M Y H:i:s", time()+432000) ." GMT");
header("Content-Type: image/jpeg");
$new_img = imagecreatetruecolor(50,75);
imagecopy($new_img, $src_img, 0, 0, $specs[0], $specs[1], 50, 75);
imagejpeg($new_img);
imagedestroy($new_img);
imagedestroy($src_img);
}
} else {
echo "SDSDSDPIJGOHGDSOHIGD";
}
}
?>
the url looks like thumbnail.php?s=100,100,subfolder,image.jpg
the first two are the x and y coordinates. i made a really old version that let you specify the height and widht of the thumbnail also, but this is always 50x75.
the thumbnail generation can be seen at <!-- m --><a class="postlink" href="http://www.outcaststudios.comWow">http://www.outcaststudios.comWow</a><!-- m --> nate, that's incredible. Good work
header("Content-Type: image/jpeg");
basically it stays in the cache for 5 days.
i should probably do it for longer, just because the url specified will always make the same thumbnail no matter what.Is the whole script done nate? I'd love to see it..well, its a module in a big CMS i made. the module cant run stand alone
the thumbnail thing is from a gallery module for my CMS, the user selects an image and then a new window opens up with the image in it and a little box that you can drag around. wherever you put the box is where the thumbnail will be. so you select where you want it and it stores it in a database.
although if all you want is the thumbnail generation:
<?php
$dir = "gallery/";
$specs = (isset($_GET['s']))?$_GET['s']:NULL;
if ($specs) {
$specs = explode(",", $specs);
$loc = $dir . $specs[2] ."/". $specs[3];
if (is_file($loc)) {
$image_type = getimagesize($loc);
$image_type = $image_type[2];
switch ($image_type) {
case 1: $src_img = imagecreatefromgif ($loc); break;
case 2: $src_img = imagecreatefromjpeg($loc); break;
case 3: $src_img = imagecreatefrompng ($loc); break;
}
if ($src_img) {
header("Expires: ". gmdate("D, d M Y H:i:s", time()+432000) ." GMT");
header("Content-Type: image/jpeg");
$new_img = imagecreatetruecolor(50,75);
imagecopy($new_img, $src_img, 0, 0, $specs[0], $specs[1], 50, 75);
imagejpeg($new_img);
imagedestroy($new_img);
imagedestroy($src_img);
}
} else {
echo "SDSDSDPIJGOHGDSOHIGD";
}
}
?>
the url looks like thumbnail.php?s=100,100,subfolder,image.jpg
the first two are the x and y coordinates. i made a really old version that let you specify the height and widht of the thumbnail also, but this is always 50x75.
the thumbnail generation can be seen at <!-- m --><a class="postlink" href="http://www.outcaststudios.comWow">http://www.outcaststudios.comWow</a><!-- m --> nate, that's incredible. Good work