2011-07-19 136 views
1

有没有人有这方面的工作?我认为图像已经被优化了。然后它被调整大小,并且尽管图片被缩小了,但它还是放弃了优化。文件大小增加。PHP - 调整大小的图像有较大的文件大小

有没有人遇到过这个。

我有一个保存在50%质量的图像。如果我复制 - >调整大小 - >保存在70%,它获得80Kb ..

有没有一种解决方案,使我能够检测图像质量之前,它?

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); 

回答

0

从技术上讲,转换的质量率不是来自jpeg数据,它只是告诉转换器在尺寸和质量之间做出哪种折衷。

有些转换器将它存储在JPEG标头的EXIF数据中,所以如果仍然存在,可以将其与exif_read_data一起使用,并查看是否返回压缩信息。

+0

Pelle ten Cate,[在superuser.com上](http://superuser.com/questions/62730/how-to-find-the-jpg-quality/62734#62734)表明ImageMagick可以确定质量即使文件没有EXIF数据保存。 – binaryLV