【问题标题】:How to compress image size while uploading to server in php?如何在php中上传到服务器时压缩图像大小?
【发布时间】:2020-07-30 22:15:03
【问题描述】:

我尝试使用此功能在上传到服务器时压缩图像。但是图片在没有减小图片大小的情况下上传。 // 压缩图片 函数 compressImage($source, $destination, $quality) {

$info = getimagesize($source);

if ($info['mime'] == 'image/jpeg') $image = imagecreatefromjpeg($source);

elseif ($info['mime'] == 'image/gif') $image = imagecreatefromgif($source);

elseif ($info['mime'] == 'image/png') $image = imagecreatefrompng($source);

imagejpeg($image, $destination, $quality);

}

【问题讨论】:

    标签: php file file-upload compress-images


    【解决方案1】:

    在上传到服务器完成后调用 PHP。在 PHP 中上传期间无法压缩图像。您在此处显示的功能只是打开已上传的图像并以您在参数中输入的质量将其保存为 JPEG 格式。

    请参阅有关 GZIP 压缩的此线程以获取请求。 Thread on StackOverflow

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-13
      • 2011-05-22
      • 1970-01-01
      • 1970-01-01
      • 2018-11-05
      • 2017-01-10
      • 2018-02-17
      相关资源
      最近更新 更多