php上传图片 不清晰,php 如何提高上传图片的画质,没有锯齿?

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中文网,转载请注明出处,感谢您的尊重!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值