$v){ $small_side = min($w,$h); $big_side = max($w,$h); $mw = $v["maxwidth"]; $mh = $v["maxheight"]; $transform = $v["transform"]; if(!is_int($mw) || $mw <= 0 || !is_int($mh) || $mh <= 0) $resamples[$k]["return"] = false; $ch = 0; $cw = 0; $th = round($mw*$h/$w); $tw = round($mh*$w/$h); //$resamples[$k]["debug"] .= "{ w : $w } { h : $h }{ mw : $mw } { mh : $mh } "; switch($transform){ case 'crop':{ //$resamples[$k]["debug"] .= "{ tw : $tw } { th : $th }"; if($th>=$mh){ $nh = ceil($th); $nw = $mw; $rh = $mh*$w/$mw; $ch = round(($h-$rh)/2); $cw = 0; //$resamples[$k]["debug"] .= " [h>=th] { nw : $nw } { nh : $nh } { ch : $ch } { cw : $cw }"; }elseif($tw>=$mw){ $nw = ceil($tw); $nh = $mh; $rw = $mw*$h/$mh; $cw = round(($w-$rw)/2); $ch = 0; //$resamples[$k]["debug"] .= " [w>=tw] { nw : $nw } { nh : $nh } { ch : $ch } { cw : $cw }"; } }break; case 'scale':{ $nh=$mh; $nw=$mw; }break; case 'max':{ if($th<=$mh){ // if($th<=$hm){ // $nh=$th; // $nh=$th; $nw=$mw; // $nw=$mw; $mh=$nh; }else{ $nw=$tw; $nh=$mh; $mw=$nw; } }break; default:break; } $newimage = imagecreatetruecolor($mw,$mh); if($type == 1 OR $type == 3){ imagealphablending($newimage, false); imagesavealpha($newimage, true); $transparent = imagecolorallocatealpha($newimage, 255, 255, 255, 127); imagefilledrectangle($newimage, 0, 0, $mw,$mh, $transparent); } imagecopyresampled($newimage,$image,0,0,$cw,$ch,$nw,$nh,$w,$h); $newpath = $basepath.$k.$filename; switch($type){ case 1: imagegif($newimage,$newpath); break; case 2: imagejpeg($newimage,$newpath,90); break; case 3: imagepng($newimage,$newpath); break; default: return false; break; }; chmod($newpath,0777); imagedestroy($newimage); $resamples[$k]["return"] = true; } return true; } ?>