jpeg_size

See all posts Reply

jpeg_size new!
by michel, 16 years, 3 months ago
Hello,

if I use
$handle->jpeg_size = 30000;
some pictures are resized at about 30 Ko, but some keep size more than 150 Ko.

What dou you think about this problem ?Reply
Re: jpeg_size new!
by colin, 16 years, 3 months ago
Well, the script tries to estimate the JPEG quality to reach the correct filesize. It tries three values, and approximates the closest one.

What images give you a 150Ko size?Reply
Re: jpeg_size new!
by michel, 16 years, 3 months ago
YOU WROTE :
What images give you a 150Ko size?

------------------------------------------

Very difficult to to say : some respect the jpeg_size rule and some never do that. Why ?Reply
Re: jpeg_size new!
by colin, 16 years, 3 months ago
Basically, the class tries to compress the images with a quality of 25, 50 and 75, and then calculates the rapport between the resulting file sizes and the wanted size, attempting to find the best quality to match the wanted size.

So if the three attempts are not linear, its estimation may be off, thus resulting in a wrong quality and filesize. If you could send me examples of the pictures that get it wrong, as well as your settings, I can try to tweak the code.Reply
Re: jpeg_size new!
by Sofus Comer, 16 years, 2 months ago
There is an explanation to why sizes differ so much when handling JPG compression. The content of an image is based on x times y pixels ofcourse but a jpg compression looks at how a picture is built. Example is if a JPG has a lot of Blue sky or large bodies of very close resembling colour pixels like night snow or any other large body it can thereby resize (ZIP) it much more than a detailed rich picture. In the example of the sky it can go ahead and group the thousands of near blue or cyan pixels and instead of letting each single pixel have its own RGB value (220,200,255) like PSDs, TIFS ect, in can save space by grouping in to Example: 26x(220,200,255), 88x((227,140,255), 4x(220,233,252) etc etc.... Thats why we see some jpgs larger or smaller than others.
Kind regards Sofus Comer, DenmarkReply
Re: jpeg_size new!
by colin, 16 years, 2 months ago
That's right. It is why I use the aforementioned method, in order to estimate the best size. We do three tries, and then use the results to calculate the best compression ratio.

It is only an estimate, and fringe cases may be wrong. But since there is no way to calculate precisely the compression in regard to the size, we attempt to get as close as possible.Reply