-
- /*
- *@im //Picture resources that need to be scaled
- *@filetype //The thumbnail file type produced
- *@dstimW //The width of the scaled picture
- *@dstimH //Height of the zoomed picture
- *@thumbname //Thumbnail file name
- // WWW.JBXUE.COM
- function makethumb($im,$dstimW,$dstimH,$thumbname,$filetype){
- //Get im The width and height of
- $pic_W=imagesx($im);
- $pic_H=imagesy($im);
- $arr = array();
- swith($filetype){
- case 'jpg':
- $arr[$ filetype]="imagejpeg";
- break;
- case 'png';
- $arr[$filetype]="imagepng";
- break;
- case 'jif';
- $arr[$filetype]="imagegif";
- }
- if(($dstimgW && $dstimgW<$pic_W) || ($dstimgH && $dstimgH<$pic_H) ){
- if($dstimgW && $dstimgW<$pic_W){
- $dsimgWratio = $dstimgW / $pic_w ;
- $resizereagW =true;
- }
- if($dstimgH && $ $dstimgH <$pic_H){
- $dsimgHratio = $dstimgH/$pic_H;
- $resizerreagH =true;
- }
- //Thumbnail width and height For the original image aspect ratio, take the smallest one
- if($resizereagW && $resizerreagH){
- if($dsimgWratio<$dsimgHratio)
- $radio = $dsimgWratio;
- else
- $radio = $dsimgHratio;
- }
- if( $resizereagW && !$resizerreagH ){
- $radio = $dsimgWratio;
- }
- if(!$resizereagW && $resizerreagH){
- $radio = $dsimgHratio ;
- }
- $imgnewW = $pic_W * $radio;
- $imgnewH = $pic_H * $radio;
- if(function_exists("imgcopyresampled")){
- //Create the target resource canvas
- $dst = imagecreatetruecolor ($imgnewW, $imgnewH);
- imagecopyresampled ($dst,$im,0,0 ,0,0,$imgnewW,$imgnewH,$pic_W,$pic_H);
- }else{
- $dst=imagecreate($imgnewW, $imgnewH);
- imagecopyresized ($dst, $im,0,0,0, 0,$imgnewW,$imgnewH,$imgnewH,$pic_W,$pic_H);
- }
- $arr[$filetype]($dst,$thumbname.".$filetype");
- imagedestroy ($dst);
- } else{//The width and height of the thumbnail itself are already greater than the width and height of the original image
- //Then the width and height of the thumbnail are the width and height of the original image
- $arr[$filetype] ($im,$thumbname.".$filetype");
- imagedestroy();
- }
- }
- ?>
Copy code
|