public function resize_image($tmp_file){
$w = 96;
$h = 96;
list($width, $height, $type) = getimagesize($tmp_file);
if($width > $w || $height > $h){
if($width >= $height){
$new_width = $w;
$x = 0;
$new_height = round($h * $height / $width);
$y = round(($h - $new_height) / 2);
}else{
$new_height = $h;
$y = 0;
$new_width = round($w * $width / $height);
$x = round(($w - $new_width) / 2);
}
}else{
$new_width = $width;
$new_height = $height;
$x = round(($w - $width) / 2);
$y = round(($h - $height) / 2);
}
$canvas = imagecreatetruecolor($w, $h);
$bcolor = imagecolorallocate($canvas, 255, 255, 255);
imagefilledrectangle($canvas,0,0,$w,$h,$bcolor);
switch($type){
case 1:
$image = imagecreatefromgif($tmp_file);
break;
case 2:
$image = imagecreatefromjpeg($tmp_file);
break;
case 3:
$image = imagecreatefrompng($tmp_file);
}
imagecopyresampled(
$canvas,
$image,
$x,
$y,
0,
0,
$new_width,
$new_height,
$width,
$height
);
switch($type){
case 1:
imagejgif($canvas, $tmp_file);
break;
case 2:
imagejpeg($canvas, $tmp_file,100);
break;
case 3:
imagepng($canvas, $tmp_file,9);
}
imagedestroy($canvas);
return true;
}