"; $newx=$x; $newy=$y; while (($newx>$maxx) ){ $newx--; $newy=$newy-$y_to_xratio; } /* while (($newy>$maxy) AND ($newx>$maxx)){ $newy--; $newx=$newx-$x_to_yratio; } */ if ($scale_up=='Y') { while ($newx<$maxx) { $newx++; $newy=$newy+$y_to_xratio; } /* while (($newy<$maxy) AND ($newx<$maxx)){ $newy++; $newx=$newx+$x_to_yratio; } */ } $newx=ceil($newx); $newy=ceil($newy); $ret[0]=$newx; $ret[1]=$newy; return $ret; } function createThumbnail($image_name,$new_width,$new_height,$scale_up="N") { //print $image_name; list($width, $height, $image_type) = getimagesize($image_name); $size=get_scale_ratio($width,$height,$new_width,$new_height,$scale_up); $new_width=$size[0]; $new_height=$size[1]; switch ($image_type) { case 1: $src_img = imagecreatefromgif($image_name); break; case 2: $src_img = imagecreatefromjpeg($image_name); break; case 3: $src_img = imagecreatefrompng($image_name); break; default: return ''; break; } $old_x = imageSX($src_img); $old_y = imageSY($src_img); if($old_x > $old_y) { $thumb_w = $new_width; $thumb_h = $old_y*($new_height/$old_x); } if($old_x < $old_y) { $thumb_w = $old_x*($new_width/$old_y); $thumb_h = $new_height; } if($old_x == $old_y) { $thumb_w = $new_width; $thumb_h = $new_height; } $thumb_w=$new_width; $thumb_h=$new_height; $dst_img = ImageCreateTrueColor($thumb_w,$thumb_h); imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); // New save location /* if($mime['mime']=='image/png'){ $result = imagepng($dst_img,$new_thumb_loc,8); } if($mime['mime']=='image/jpg'){ $result = imagejpeg($dst_img,$new_thumb_loc,80); } if($mime['mime']=='image/jpeg'){ $result = imagejpeg($dst_img,$new_thumb_loc,80); } if($mime['mime']=='image/pjpeg'){ $result = imagejpeg($dst_img,$new_thumb_loc,80); } */ ob_start(); switch ($image_type) { case 1: imagegif($dst_img); break; case 2: imagejpeg($dst_img, NULL, 100); break; // best quality case 3: imagepng($dst_img, NULL, 0); break; // no compression default: echo ''; break; } $final_image = ob_get_contents(); ob_end_clean(); if ($image_type==1){ header("Content-Type: image/gif"); } else if ($image_type==2){ header("Content-Type: image/jpeg"); } else if ($image_type==3){ header("Content-Type: image/png"); } print $final_image; imagedestroy($dst_img); imagedestroy($src_img); } ?>