<?php
$source = '300x300.jpg';
$thumb = '158x158.jpg';createThumb($source, $thumb, 158, 158);echo '<img src="'.$source.'"><br>';
echo '<img src="'.$thumb.'">';function createThumb($source, $thumb, $width, $height){ list($owidth,$oheight,$otype) = getimagesize($source);
switch($otype){
case 1: $source_img = imagecreatefromgif($source); break;
case 2: $source_img = imagecreatefromjpeg($source); break;
case 3: $source_img = imagecreatefrompng($source); break;
default: return false;
}
$new_img = imagecreatetruecolor($width, $height);
imagecopyresampled($new_img, $source_img, 0, 0, 0, 0, $width, $height, $owidth, $oheight); $filename = basename($thumb);
list($name, $ext)= explode('.', $filename); $ext_type = 0; switch(strtolower($ext)){
case 'jpg':
case 'jpeg':
$ext_type = 2;
break;
case 'gif':
$ext_type = 1;
break;
case 'png':
$ext_type = 3;
break;
} switch($ext_type){
case 1: imagegif($new_img, $thumb, 100); break;
case 2: imagejpeg($new_img, $thumb, 100); break;
case 3: imagepng($new_img, $thumb, 100); break;
} imagedestroy($source_img);
imagedestroy($new_img);}?>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货