PHP-调整大小的图像具有更大的文件大小 [英] PHP - Resized image has larger file size

查看:132
本文介绍了PHP-调整大小的图像具有更大的文件大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人为此解决吗?我认为图像已经优化.然后调整其大小,并放弃优化,尽管图片缩小了.文件大小增加.

Does anyone have a work around for this? I think that the image is already optimised. It then get's resized and it sheds its optimization and despite the picture being made narrowly smaller. The file size increases.

以前有没有人碰过这个.

Has anyone come across this before.

我有一个图像以50%的质量保存.如果我复制->调整大小->保存70%,则可获取80Kb.

I have an image that was saved at 50% quality. If I copy -> resize -> save at 70% it gains 80Kb..

有没有可以让我在图像进入之前检测图像质量的解决方案?

Is there a solution which allows me to detect the quality of the image before it goes in?

function resize($width,$height) {
    $new_image = imagecreatetruecolor($width, $height);

    imagesavealpha($new_image, true);
    $trans_colour = imagecolorallocatealpha($new_image, 0, 0, 0, 127);
    imagefill($new_image, 0, 0, $trans_colour); 

    imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
    $this->image = $new_image;
}

...

imagejpeg($this->image,$filename,$compression);

推荐答案

从技术上讲,转换的质量率不能从jpeg数据得出,它只是告诉转换器在大小和质量之间进行权衡.

Technically, the quality rate of the conversion is not derivable from the jpeg data, it just tells the converter which tradeoff to make between size and quality.

尽管有些转换器将其存储在JPEG标头的EXIF数据中,所以如果仍然存在,则可以将其与

Some converters store it in the EXIF data of the JPEG header though, so if that is still present you can use it with exif_read_data on it, and see if the compression information is returned.

这篇关于PHP-调整大小的图像具有更大的文件大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆