I have a function to scale down images, and it works fine. Here is the function:
<?php
function resize($filename, $max_width=200) {
$type = preg_replace('#.*?\.(.+)$#i', '\\1', $filename);
if ( stristr($filename, '.jpg') ) {
$type = 'jpeg';
}
$func = 'imagecreatefrom' . $type;
// Content type
//header('Content-type: image/' . $type);
// Get new dimensions
list($width, $height) = getimagesize($filename);
//$new_width = $width * $percent;
//$new_height = $height * $percent;
//$max_width = 200;
# Calculate percent
$per = $width/$max_width;
$new_width = $width / $per;
$new_height = $height / $per;
// Resample
$image_p = imagecreatetruecolor($new_width, $new_height) or die ('imagecreatetruecolor failed');
$image = $func($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height) or die ('imagecopy failed');
// Output
imagejpeg($image_p, $_SERVER['DOCUMENT_ROOT'] . '/images/tmp.jpeg', 100) or die ('imagejpg failed');
}
?>
Anyway, that works fine and dandy, but what if I need to resize say, 100 images on the same page? I got it working for one page where only one picture needs to be resized, but I'm making a friends system like Myspace has and in that case, tons of pics could need resizing.
How would I go about storing these files on the server and keeping track of them? Also, I would like to cleanup the mess of files each script creates at the end of it.