Friday, December 23, 2016

save - Why does a JPEGs file size increase after cropping and saving for web in Photoshop?


When I save my image for the web in Adobe Photoshop, the produced jpeg is larger than the original jpeg file. The only alteration done to the image is cropping.


How is this possible? I am saving the jpeg at 30 quality.



Answer



Although the question was asked about Adobe Photoshop, the behavior is due to the lossy JPEG format and would be similar with any image editor.


Cropping a JPEG can make it less compressible, especially when the x and y offsets of the cropped area are odd numbers. This causes a re-subsampling of the color channels that can make the cropped image more complex and thus less compressible.


Also if the cropping offsets are not divisible by 8, the 8x8 tiles used in JPEG compression are now made up of parts of several adjacent tiles from the original JPEG, and that can increase the image complexity.


There are other things that can come into play (addition of a color profile, etc.) but without access to your before-and-after images it's hard to tell what exactly happened. Most likely, though, it's the cropping offset effect described above.


Results would depend upon the nature of the image. I experimented with a 500x500-pixel checkerboard of 100x100-pixel squares, compressed with quality 50, then cropped to 490x490 pixels and recompressed with quality 50.


The resulting sizes are:



original:                     3968 bytes
cropped with 1-pixel offsets: 5445 bytes
cropped with 2-pixel offsets: 5279 bytes
cropped with 3-pixel offsets: 5481 bytes
cropped with 4-pixel offsets: 4426 bytes
cropped with 8-pixel offsets: 3917 bytes

For a photograph, on the other hand, results are more in line with intuition, the cropped photo having a slightly smaller file size than the original:


comressed with quality 50:    57413 bytes
cropped with 3-pixel offsets: 56576 bytes

cropped with 4-pixel offsets: 56170 bytes

I used ImageMagick, not Photoshop, for these experiments, but I'm sure that Photoshop would exhibit similar behavior for these tests.


No comments:

Post a Comment

technique - How credible is wikipedia?

I understand that this question relates more to wikipedia than it does writing but... If I was going to use wikipedia for a source for a res...