function resizeImg($from,$w=100,$h=100,$newfile){ $info = getimagesize($from); switch ($info[2]){ case 1: $im = imagecreatefromgif($from); break; case 2: $im = imagecreatefromjpeg($from); break; case 3: $im = imagecreatefrompng($from); break; default: //exit('不支持的图像格式'); break; } $temp = pathinfo($from); $name = $temp["basename"];//文件名 $dir = $temp["dirname"];//文件所在的文件夹 $extension = $temp["extension"];//文件扩展名 $width = $info[0];//获取图片宽度 $height = $info[1];//获取图片高度 $per1 = round($width/$height,2);//计算原图长宽比 $per2 = round($w/$h,2);//计算缩略图长宽比 //计算缩放比例 if($per1>$per2||$per1==$per2) { //原图长宽比大于或者等于缩略图长宽比,则按照宽度优先 $per=$w/$width; } if($per1
还有一段代码如下
$file = $_FILES["photo"];$filename=$file["tmp_name"]; $size=$file['size']; $type=$file['type']; $max_size=5*1024*1024;//echo $size;if($type!="image/jpg"&&$type!="image/jpeg"&&$type!="image/png"&&$type!="image/gif"){ echo"";exit;} if($size>$max_size){ echo"";exit;} $udid=guid();$target_file="../photos/".$udid.".jpg";copy($filename,$target_file);/*$info=getimagesize($target_file); print_r($info);*/resizeImg($target_file,$nw,$nh,$target_file);$ifn = $target_file; //-----------原图像----$ofn = $target_file; //---剪切后保存的图像名----$ext = strtoupper(end(explode('.',$ifn))); if(is_file($ifn) && ($ext == "JPG" || $ext == "JPEG")){ $source = imagecreatefromjpeg($ifn); }elseif(is_file($ifn) && $ext == "PNG"){ $source = imagecreatefromPNG($ifn); }elseif(is_file($ifn) && $ext == "GIF"){ $source = imagecreatefromGIF($ifn); } $sourceWidth = imagesx($source); $sourceHeight = imagesy($source); $thumbWidth = $_POST['w']; $thumbHeight = $_POST['h']; $thumb = imagecreatetruecolor($thumbWidth, $thumbHeight); $x1 = $_POST['x1']; $y1 = $_POST['y1']; $x2 = $_POST['x2']; $y2 = $_POST['y2']; imagecopyresampled($thumb, $source,0,0,$x1,$y1,$thumbWidth,$thumbHeight,$thumbWidth,$thumbHeight); imagejpeg($thumb, $ofn);resizeImg($target_file,100,100,$target_file);
您能帮忙看看问题在哪吗?因为对GD函数不熟悉,希望您能指导指导,谢谢
尝试启用抗锯齿功能(imageantialias)
不过你对位图做了缩放,丢失精度是必然的
尝试启用抗锯齿功能(imageantialias)
不过你对位图做了缩放,丢失精度是必然的
试了,好像没有效果呢!!!
所以说是“尝试”
好吧,继续尝试!
找到问题了,不过还是谢谢斑竹的指导
原来是这两个函数有关系,呵呵!以后得注意了
本文原创发布php中文网,转载请注明出处,感谢您的尊重!