Forum Moderators: coopster

Message Too Old, No Replies

imagejpeg() compression is barely having an affect on file size!

         

NeedExpertHelp

3:45 pm on Jul 26, 2010 (gmt 0)

10+ Year Member



Hi,

I'm using imagejpeg() to reduce the size of incoming .jpg's after resizing them.

However, the compression is barely having an affect on the size.

For example, if I use 75 for the Quality parameter, I get a 21KB file that's pretty good quality, but if I use 01 for Quality, I get an image that is unrecognizable from the original (due to the heavy compression) but that is still 18KB large!

When using a graphics program in Windows, I can get the same file down to about 12KB without any difference compared to the imagejpeg() Quality at 75, so there is clearly something wrong here.

Is the imagejpeg() compression just that bad or am I doing something wrong? Also, is there any other way to compress incoming jpg's that is much more efficient/better than imagejpeg()?

Thanks!

rocknbil

4:39 pm on Jul 26, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As for better, you may have more luck with InageMagick/Imagick, it certainly gets around many of the memory issues and constraints of GD and will likely have more control (or maybe not.) A couple things of note: the valid ranges of imagejpeg are 1 - 100, so presuming it's doing a quality of 1. manual [php.net] I'm guessing you've played around with other values, it is based off the GD library which has it's limitations.

NeedExpertHelp

4:51 pm on Jul 26, 2010 (gmt 0)

10+ Year Member



Hi rocknbil,

I guess I'll give ImageMagick/Imageick a try, because I am thoroughly disappointed with GD's image compression.

Again, when I set it the Quality to 1, the image was not recognizable due to the massive amounts of compression, yet the image file was still 18KB (vs 21KB @ Quality 75).

Does anyone else have any other ideas about why the GD compression is so horrible?

Thanks!

astupidname

12:26 am on Jul 27, 2010 (gmt 0)

10+ Year Member



That's odd you have this problem, I just ran my own test, as I've never had such problem you mention with GD re-qualitizing before. And still don't, guess it's just you! Sorry! :)

Image used was a .jpg file measuring 619 x 930 at 127kb originally. Only quality level was altered, image dimensions were not changed.

Results:

(Quality level used) = (Resulting file size, [127KB original])
100% = 351.03KB
95% = 198.01KB
90% = 143.84KB
85% = 120.4KB
80% = 107.66KB
75% = 91.18KB
70% = 79.91KB
65% = 72.83KB
60% = 62.16KB
55% = 55.48KB
50% = 50.91KB
45% = 47.4KB
40% = 44.1KB
35% = 40.87KB
30% = 34.76KB
25% = 30.58KB
20% = 25.89KB
15% = 21.29KB
10% = 16.92KB
5% = 12.54KB

with an entry of 01 for the quality percentage, 11.03KB



It is strange that with GD when you use higher percentages the file size actually increases. And the point at which this occurs (i.e. 87% or 98% etc..) varies from image to image also. I guess it may be dependant upon the origins of the file and whether it's been processed in some way before and how, but appears to be usually between 85% to 98%.
Generally, I would not suggest going below 50% (even at 50% quality loss can be quite significant), with about 65 to 75% probably being safest bet for maintaining some semblence of quality.
I have not, however, ran upon a case where the quality adjustment would not change the file size significantly. Could you be having some kind of caching issue?

tangor

2:37 am on Jul 27, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Do all jpgs act the same? Is it not possible that some submitted have already been highly compressed?

When working with 10s of thousands images a bit of tweak in size might have benefit. There comes a breakpoint between quality, quantity and bandwidth!

penders

7:56 am on Jul 27, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



May be you're seeing the difference between standard and progressive(interlaced) JPEGs? I've found progressive JPEGs to often produce a slightly smaller filesize - at least when saving from my graphics app. (Progressive JPEGs... you see a low quality whole image at first that then refines as the image loads, rather than loading from top to bottom as with a standard JPEG.)

Note: If you want to output Progressive JPEGs, you need to set interlacing on with imageinterlace() [php.net].


...the valid ranges of imagejpeg are 1 - 100


The manual states 0 to 100.

It is strange that with GD when you use higher percentages the file size actually increases.


Like you say, the original image will already have had some compression applied. I suppose in theory, if you open a JPEG that has already been compressed at 75% and resave it at 75% with imagejpeg() then it should be the same size?!