在每个屏幕上以高质量显示已调整大小的图像

时间:2017-12-05 06:25:38

标签: javascript php jquery

当我尝试在PHP中调整图像大小时,它会在某些屏幕上变得模糊。有没有办法在每个屏幕上以高质量显示已调整大小的图像?

这是我到目前为止所尝试的内容:

if($thumb == TRUE)
    {
        $thumbnail = $thumb_path.$fileName;
        list($width,$height) = getimagesize($upload_image);
        $thumb_create = imagecreatetruecolor($thumb_width,$thumb_height);
        switch($file_ext){
            case 'jpg':
                $source = imagecreatefromjpeg($upload_image);
                break;
            case 'jpeg':
                $source = imagecreatefromjpeg($upload_image);
                break;

            case 'png':
                $source = imagecreatefrompng($upload_image);
                break;
            case 'gif':
                $source = imagecreatefromgif($upload_image);
                break;
            default:
                $source = imagecreatefromjpeg($upload_image);
        }

        imagecopyresized($thumb_create,$source,0,0,0,0,$thumb_width,$thumb_height,$width,$height);
        switch($file_ext){
            case 'jpg' || 'jpeg':
                imagejpeg($thumb_create,$thumbnail,100);
                break;
            case 'png':
                imagepng($thumb_create,$thumbnail,100);
                break;

            case 'gif':
                imagegif($thumb_create,$thumbnail,100);
                break;
            default:
                imagejpeg($thumb_create,$thumbnail,100);
        }

1 个答案:

答案 0 :(得分:0)

使用高质量的图像,或者您甚至可以使用srcset属性。

示例

<picture>
  <source media="(min-width: 650px)" srcset="big.jpg">
  <source media="(min-width: 465px)" srcset="medium.jpg">
  <img src="small.jpg" alt="Flowers" style="width:auto;">
</picture>

Try it