原创dedecms缩略图系列教程:解决dedecms缩略图缩放变形问题
001if(!function_exists(ImageResize))002{003functionImageResize($srcFile,$toW,$toH,$toFile=“”)004{005global$cfg_photo_type;006if($toFile==“”)007{008$toFile=$srcFile;009}010$info=“”;011$srcInfo=GetImageSize($srcFile,$info);012switch($srcInfo[2])013{014case1:015if(!$cfg_photo_type[gif])016{017returnfalse;018}019$im=imagecreatefromgif($srcFile);020break;021case2:022if(!$cfg_photo_type[jpeg])023{024returnfalse;025}026$im=imagecreatefromjpeg($srcFile);027break;028case3:029if(!$cfg_photo_type[png])030{031returnfalse;032}033$im=imagecreatefrompng($srcFile);034break;035case6:036if(!$cfg_photo_type[bmp])037{038returnfalse;039}040$im=imagecreatefromwbmp($srcFile);041break;042}043$srcW=ImageSX($im);044$srcH=ImageSY($im);045if($srcW<=$toW&&$srcH<=$toH)046{047returntrue;048}049//缩略生成并裁剪050$newW=$toH*$srcW/$srcH;051$newH=$toW*$srcH/$srcW;052if($newH>=$toH)053{054$ftoW=$toW;055$ftoH=$newH;056}057else058{059$ftoW=$newW;060$ftoH=$toH;061}062if($srcW>$toW||$srcH>$toH)063{064if(function_exists(“imagecreatetruecolor”))065{066@$ni=imagecreatetruecolor($ftoW,$ftoH);067if($ni)068{069imagecopyresampled($ni,$im,0,0,0,0,$ftoW,$ftoH,$srcW,$srcH);070}071else072{073$ni=imagecreate($ftoW,$ftoH);074imagecopyresized($ni,$im,0,0,0,0,$ftoW,$ftoH,$srcW,$srcH);075}076}077else078{079$ni=imagecreate($ftoW,$ftoH);080imagecopyresized($ni,$im,0,0,0,0,$ftoW,$ftoH,$srcW,$srcH);081}082//裁剪图片成标准缩略图083$new_imgx=imagecreatetruecolor($toW,$toH);084if($newH>=$toH)085{086imagecopyresampled($new_imgx,$ni,0,0,0,($newH–$toH)/2,$toW,$toH,$toW,$toH);087}088else089{090imagecopyresampled($new_imgx,$ni,0,0,($newW–$toW)/2,0,$toW,$toH,$toW,$toH);091}092switch($srcInfo[2])093{094case1:095imagegif($new_imgx,$toFile);096break;097case2:098imagejpeg($new_imgx,$toFile,85);099break;100case3:101imagepng($new_imgx,$toFile);102break;103case6:104imagebmp($new_imgx,$toFile);105break;106default:107returnfalse;108}109imagedestroy($new_imgx);110imagedestroy($ni);111}112imagedestroy($im);113returntrue;114}115}AD:【百度云分享】大学生必备,互联网精品福利资源下载
标签:织梦
上一篇响应式自适应和带手机端的区别下一篇2021 现在发布外链还有用吗