用GD生成缩略图
时间:2006-01-13 来源:gydoesit
转的,原文地址不见了
$small_image_name="image_name";
// 生成图片的宽度
$resizewidth=400;
// 生成图片的高度
$resizeheight=400;
function ResizeImage($im,$maxwidth,$maxheight,$name){
$resizewidth = false;
$resizeheight = false;
$widthratio = 0;
$heightratio = 0;
$width = imagesx($im);
$height = imagesy($im);
//如果最大不为零,且大于
if(($maxwidth && $width > $maxwidth) || ($maxheight && $height > $maxheight)){
if($maxwidth && $width > $maxwidth){
$widthratio = $maxwidth/$width;
$resizewidth=true;
}
if($maxheight && $height > $maxheight){
$heightratio = $maxheight/$height;
$resizeheight=true;
}
if($resizewidth && $resizeheight){
if($widthratio
if(!empty($_FILES['image']['size'])){
if($_FILES['image']['type'] == "image/pjpeg"){
$im = imagecreatefromjpeg($_FILES['image']['tmp_name']);
}elseif($_FILES['image']['type'] == "image/x-png"){
$im = imagecreatefrompng($_FILES['image']['tmp_name']);
}elseif($_FILES['image']['type'] == "image/gif"){
$im = imagecreatefromgif($_FILES['image']['tmp_name']);
}
if($im){
if(file_exists("$small_image_name.jpg")){
unlink("$small_image_name.jpg");
}
ResizeImage($im,$resizewidth,$resizeheight,$small_image_name);
ImageDestroy ($im);
}
}
?>
">
$small_image_name="image_name";
// 生成图片的宽度
$resizewidth=400;
// 生成图片的高度
$resizeheight=400;
function ResizeImage($im,$maxwidth,$maxheight,$name){
$resizewidth = false;
$resizeheight = false;
$widthratio = 0;
$heightratio = 0;
$width = imagesx($im);
$height = imagesy($im);
//如果最大不为零,且大于
if(($maxwidth && $width > $maxwidth) || ($maxheight && $height > $maxheight)){
if($maxwidth && $width > $maxwidth){
$widthratio = $maxwidth/$width;
$resizewidth=true;
}
if($maxheight && $height > $maxheight){
$heightratio = $maxheight/$height;
$resizeheight=true;
}
if($resizewidth && $resizeheight){
if($widthratio
if(!empty($_FILES['image']['size'])){
if($_FILES['image']['type'] == "image/pjpeg"){
$im = imagecreatefromjpeg($_FILES['image']['tmp_name']);
}elseif($_FILES['image']['type'] == "image/x-png"){
$im = imagecreatefrompng($_FILES['image']['tmp_name']);
}elseif($_FILES['image']['type'] == "image/gif"){
$im = imagecreatefromgif($_FILES['image']['tmp_name']);
}
if($im){
if(file_exists("$small_image_name.jpg")){
unlink("$small_image_name.jpg");
}
ResizeImage($im,$resizewidth,$resizeheight,$small_image_name);
ImageDestroy ($im);
}
}
?>
">
相关阅读 更多 +