& Lt ;? Php *** generate a thumbnail ** @ authoryangzhiguo0903@163.com * @ paramstring source image absolute complete address {with file name and suffix name} * @ paramstring target Image absolute complete address {with file name and suffix name} * @ paramint thumbnail width {0: the target height cannot be
$ Src_w & $ height> $ src_h) | ($ height> $ src_h & $ width = 0) | ($ width> $ src_w & $ height = 0) {$ proportion = 1;} if ($ width> $ src_w) {$ dst_w = $ width = $ src_w;} if ($ height> $ src_h) {$ dst_h = $ height = $ src_h;} if (! $ Width &&! $ Height &&! $ Proportion) {return false;} if (! $ Proportion) {if ($ cut = 0) {if ($ dst_w & $ dst_h) {if ($ dst_w/$ src_w> $ dst_h/$ src_h) {$ dst_w = $ src_w * ($ dst_h/$ src_h); $ x = 0-($ dst_w-$ width)/2 ;} else {$ dst_h = $ src_h * ($ dst_w/$ src_w); $ y = 0-($ dst_h-$ height)/2 ;}} else if ($ dst_w xor $ dst_h) {if ($ dst_w &&! $ Dst_h) // Has width and height {$ propor = $ dst_w/$ src_w; $ height = $ dst_h = $ src_h * $ propor;} else if (! $ Dst_w & $ dst_h) // high and no width {$ propor = $ dst_h/$ src_h; $ width = $ dst_w = $ src_w * $ propor ;}}} else {if (! $ Dst_h) // no height during cropping {$ height = $ dst_h = $ dst_w;} if (! $ Dst_w) // no width during cropping {$ width = $ dst_w = $ dst_h;} $ propor = min (max ($ dst_w/$ src_w, $ dst_h/$ src_h ), 1); $ dst_w = (int) round ($ src_w * $ propor); $ dst_h = (int) round ($ src_h * $ propor ); $ x = ($ width-$ dst_w)/2; $ y = ($ height-$ dst_h)/2 ;}} else {$ proportion = min ($ proportion, 1); $ height = $ dst_h = $ src_h * $ proportion; $ width = $ dst_w = $ src_w * $ proportion;} $ src = $ createfun ($ src_img); $ dst = Imagecreatetruecolor ($ width? $ Width: $ dst_w, $ height? $ Height: $ dst_h); $ white = imagecolorallocate ($ dst, 255,255,255); imagefill ($ dst, 0, 0, $ white); if (function_exists ('imagecopyresampled ')) {imagecopyresampled ($ dst, $ src, $ x, $ y, 0, 0, $ dst_w, $ dst_h, $ src_w, $ src_h);} else {imagecopyresized ($ dst, $ src, $ x, $ y, 0, 0, $ dst_w, $ dst_h, $ src_w, $ src_h);} $ otfunc ($ dst, $ dst_img ); imagedestroy ($ dst); imagedestroy ($ src); return true ;}
function fileext($file){ return pathinfo($file, PATHINFO_EXTENSION);}