I wrote and image resize script that keeps the same width height ratio as the orignal what I want to do is take the resized thumbnail and center a 100 by 100 pixel box on it so that my thumbnails are now 100 X 100. It would make my gallery look proportional and neatly in order. How would you go about doing this.
here is the code that I wrote
if($width > $height) {
$thumbnail_width = 100;
$thumbnail_height = (int)(100 * ($size[1] / $size[0]));
}
else {
$thumbnail_width = (int)(100 * ($size[0] / $size[1]));
$thumbnail_height = 100;
}
// Read the source file
$source_handle = $function_to_read($image_dir.'/'.$photo_category.'/images/'.$filename);
if($source_handle) {
if($function_suffix == $photo_types['image/gif']) {
// Create a blank image for gif files
$destination_handle = imagecreate($thumnail_width, $thumbnail_height);
}
else {
// Create a blank image for everything that is not a gif files
$destination_handle = imagecreatetruecolor($thumbnail_width,$thumbnail_height);
}
// Let's create an blank image for the thumbnail
// Take the blank file image(destinayion_handle)
// and fill it with the uploaded image($source_handle)
imagecopyresized($destination_handle, $source_handle, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $size[0], $size[1]);
}
else {
echo 'Uploaded file does not exist <br />';
$text = 'ERROR!! Could not find '.$image_dir.'/'.$photo_category.'/images/'.$filename.' to create the thumbnail for IP('.$_SERVER['REMOTE_ADDR'].')\n';
fwrite($fileLog_handle, $text);
exit();
}
// Let's save the thumbnail
$function_to_write($destination_handle, $image_dir.'/'.$photo_category.'/thumbs/tb_'.$filename);
imagedestroy($destination_handle);