
mime");
$arr = getNewSize($maxWidth, $maxHeight, $srcWidth, $srcHeight);
$thumbWidth = $arr['width'];
$thumbHeight = $arr['height'];
if ($isJpeg) {
$dstThumbPic = imagecreatetruecolor($thumbWidth, $thumbHeight);
$srcPic = imagecreatefromjpeg($srcFile);
imagecopyresampled($dstThumbPic, $srcPic, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $srcWidth, $srcHeight);
//imagecopyresized($dstThumbPic, $srcPic, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $srcWidth, $srcHeight);
imagejpeg($dstThumbPic, 'p1_thumb.jpg', 100);
imagedestroy($dstThumbPic);
imagedestroy($srcPic);
} elseif ($isGif) {
//$dstThumbPic = imagecreate($thumbWidth, $thumbHeight); /* attention */
$dstThumbPic = imagecreatetruecolor($thumbWidth, $thumbHeight); /* attention */
//创建透明画布
imagealphablending($dstThumbPic, true);
imagesavealpha($dstThumbPic, true);
$trans_colour = imagecolorallocatealpha($dstThumbPic, 0, 0, 0, 127);
imagefill($dstThumbPic, 0, 0, $trans_colour);
$srcPic = imagecreatefromgif($srcFile);
imagecopyresampled($dstThumbPic, $srcPic, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $srcWidth, $srcHeight);
//imagecopyresized($dstThumbPic, $srcPic, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $srcWidth, $srcHeight);
imagegif($dstThumbPic, 'p2_thumb.gif');
imagedestroy($dstThumbPic);
imagedestroy($srcPic);
} elseif ($isPng) {
$dstThumbPic = imagecreatetruecolor($thumbWidth, $thumbHeight);
//创建透明画布
imagealphablending($dstThumbPic, true);
imagesavealpha($dstThumbPic, true);
$trans_colour = imagecolorallocatealpha($dstThumbPic, 0, 0, 0, 127);
imagefill($dstThumbPic, 0, 0, $trans_colour);
$srcPic = imagecreatefrompng($srcFile);
imagecopyresampled($dstThumbPic, $srcPic, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $srcWidth, $srcHeight);
//imagecopyresized($dstThumbPic, $srcPic, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $srcWidth, $srcHeight);
imagepng($dstThumbPic, 'p3_thumb.png');
imagedestroy($dstThumbPic);
imagedestroy($srcPic);
} else {
return false;
}
} else {
return false;
}
}
/* 缩略图长宽限制 */
$thumbMaxWidth = "400";
$thumbMaxHeight = "400";
/* 浏览图长宽限制 */
$browseMaxWidth = "400";
$browseMaxHeight = "400";
foreach ($arrFile as $file) {
makeThumb($file, 'images/', $thumbMaxWidth, $thumbMaxHeight);
}
die('ok');
?>| 欢迎光临 PHP开发笔记 (http://www.phpvi.com/) | Powered by Discuz! 6.1.0 |