class.upload.php is a powerful and mature PHP class to manage uploaded files, and manipulate images in many ways. The script is available under a GPL license.
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
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
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
if I use
some pictures are resized at about 30 Ko, but some keep size more than 150 Ko.
What dou you think about this problem ?
What images give you a 150Ko size?
What images give you a 150Ko size?
------------------------------------------
Very difficult to to say : some respect the jpeg_size rule and some never do that. Why ?
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.
Kind regards Sofus Comer, Denmark
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.