加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php调整图像没有损失质量

发布时间:2020-12-13 14:07:57 所属栏目:PHP教程 来源:网络整理
导读:我已经实现了这个方法(通过以下php教程)来创建图像的预览: function createPreview($image_path,$filename) { header('Content-Type: image/jpeg'); $thumb = imagecreatetruecolor(350,350); $source = imagecreatefromjpeg($image_path); list($width,$he
我已经实现了这个方法(通过以下php教程)来创建图像的预览:
function createPreview($image_path,$filename) {

    header('Content-Type: image/jpeg');
    $thumb = imagecreatetruecolor(350,350);
    $source = imagecreatefromjpeg($image_path);

    list($width,$height) = getimagesize($image_path);

    imagecopyresized($thumb,$source,350,$width,$height);

    imagejpeg($thumb,$filename."_prev.jpg");
}

但我注意到缩放图像损失了很多质量.我怎样才能保持缩放图像的质量(我不能使用想象力,我的服务器不支持它)

imagejpeg默认使用75质量.所以你需要明确定义它.
imagejpeg($thumb,$filename."_prev.jpg",100);

另外,使用imagecopyresampled

imagecopyresampled() copies a rectangular portion of one image to another image,smoothly interpolating pixel values so that,in particular,reducing the size of an image still retains a great deal of clarity.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读