0
votes

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.

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

1 Answers

0
votes

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.

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.