This works nicely for me:
function resize($start_path,$end_path,$end_width,$type)
{
$picture_location = "$start_path";
$picture_save = "$end_path";
$size = $end_width; // size in pixel u want the picture to come out
$im_size = GetImageSize ( $picture_location);
$imageWidth = $im_size[0];
$imageHeight = $im_size[1];
// - or with GD 2+ -
// do all your color allocations here
//$font_color_black = ImageColorAllocate( $im, 0,0,0);
if ($type == JPEG){
$im2 = ImageCreateFromJPEG($picture_location);
}
if ($type == PNG){
$im2 = ImageCreateFromPNG($picture_location);
}
if ($imageWidth>=$imageHeight)
{
$width=$size;
$height = ($width/$imageWidth)*$imageHeight;
}
else
{
$height=$size;
$width = ($height/$imageHeight)*$imageWidth;
}
$im = imageCreateTrueColor( $width, $height );
ImageCopyResized ($im,$im2, 0, 0, 0, 0, $width, $height, $imageWidth, $imageHeight);
//the number (100) determines image quality - I have mine set to 80%
//Imagejpeg($im,'',100); to print to screen
if ($type == JPEG){
Header("Content-type: image/jpeg");
ImageJPEG($im,$picture_save,80);
}
if ($type == PNG){
Header("Content-type: image/png");
ImagePNG($im,$picture_save,80);
}
ImageDestroy($im);
ImageDestroy ($im2);
}
if ($fupload_type == "image/x-png"){
resize("$path_to_image location/$uploaded_image_filename","$destination_thumbnail_directory/$desired_thumb_filename","100","PNG");
resize("$path_to_image location/$uploaded_image_filename","$destination_full_size_directory/$desired_filename","450","PNG");
}
if ($fupload_type == "image/pjpeg"){
resize("$path_to_image location/$uploaded_image_filename","$destination_thumbnail_directory/$desired_thumb_filename","100","JPEG");
resize("$path_to_image location/$uploaded_image_filename","$destination_full_size_directory/$desired_filename","450","JPEG");
}
I just resample everything at 80% but you could alter the code to feed in the resample percentage like
$uploaded_image_filename","$destination_full_size_directory/$desired_filename","450","JPEG", "80");
and then feed that number into the ImageJPEG() command