日期:2014-05-17  浏览次数:20497 次

php生成缩略图的更能,遇到点问题,请教各位
想实现一个上传图片并生成缩略图的功能,从网上找了断代码,也成功了。
想一次生成两张——一张大缩略图,一张小缩略图,结果就提是下面的代码:

Notice: Undefined variable: RESIZEWIDTH in D:\WWW\qiangyuan\up.php on line 17
Notice: Undefined variable: RESIZEWIDTH in D:\WWW\qiangyuan\up.php on line 23



源程序代码如下:

<?php
//****************************************
//生成缩略图========================================

function ResizeImage($im,$maxwidth,$maxheight,$name){ 
$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 < $heightratio){ 
$ratio = $widthratio; 
}else{ 
$ratio = $heightratio; 

}elseif($RESIZEWIDTH){ 
$ratio = $widthratio; 
}elseif($RESIZEHEIGHT){ 
$ratio = $heightratio; 

$newwidth = $width * $ratio; 
$newheight = $height * $ratio; 
if(function_exists("imagecopyresampled")){ 
$newim = imagecreatetruecolor($newwidth, $newheight); 
imagecopyresampled($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); 
}else{ 
$newim = imagecreate($newwidth, $newheight); 
imagecopyresized($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); 

ImageJpeg ($newim,$name . ".jpg"); 
ImageDestroy ($newim); 
}else{ 
ImageJpeg ($im,$name . ".jpg"); 

}

$FILENAME="product/min/".date("YmdHis"); //小图片文件名
$RESIZEWIDTH=150; // 生成图片的宽度
$RESIZEHEIGHT=113; // 生成图片的高度 



if(isset($_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("$FILENAME.jpg")){ 
unlink("$FILENAME.jpg"); 


ResizeImage($im,$RESIZEWIDTH,$RESIZEHEIGHT,$FILENAME); //生成小图
ResizeImage($im,600,450,"product/max/".date("YmdHis")); //生成大图
ImageDestroy ($im); 



//****************************************
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
body,td,th {
color: #FF0000;
font-size: 12px;
}
body {
margin-left: 2px;
margin-top: 2px;
margin-right: 2px;
margin-bottom: 0px;
background-color: #e3efe7;
}
-->
</style>
</head>
<body>

 <form name="form1" action="" enctype="multipart/form-data" method="post">

  <input name="image" type="file"> 
  <input type=&