Okay, the last problem I have is pretty minute, I think. I can't think of how to functionize this code I've written. It's fairly adaptable to all sorts of images and since I only need them to be scaled down to a max width, and height is irrelevant, I wrote a nice and simple resizing program in it as well.
Here is my code:
function resize($filename)
$type = preg_replace('#.*?\.(.+)$#i', '\\1', $filename);
if ($type == '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);
$image = $func($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
// Output
imagejpeg($image_p, 'template.jpeg', 100);
}
resize('template.gif') or die ('Could not execute');
Well, the file template.gif worked before, but now it won't since I put it in a function, and none of the files will. Without the function it was working fine; however, I still never reached the Could not execute error message, so it seems a bit odd the function isn't performing as it should but it isn't dying.
Perhaps I should slap a "return false;" for some circumstances in there? Oh well, could you guys see waht's wrong with this function and tell me how to make it into one?