Home  >  Article  >  Backend Development  >  php生成缩略图的更能,遇到点有关问题

php生成缩略图的更能,遇到点有关问题

WBOY
WBOYOriginal
2016-06-13 13:34:35969browse

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



源程序代码如下:

//****************************************
//生成缩略图========================================

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 $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); 



//****************************************
?>







 


   
 
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn