Changing the JPG quality in WordPress

Sometimes, people say some silly things, only because they don’t know any better (not trying to pick on Raelene too much, there are plenty of other people that have written similar articles). So I’d like to set the record straight, and introduce a new feature in EWWW I.O.

The first misconception many have about JPEG quality is that it is a percentage. It is nothing of the sort. Rather, it is a quality slider, and the values don’t even have to be 1-100. If you’ve used Photoshop, the scale is 1-12, but it operates the same way as the typical 1-100 range that is used by WordPress (via GD, Imagick, or GMagick). The scale is also not linear, it’s more exponential (although technically I think it might be logarithmic). This means that the higher you go, the less quality improvement there is, but the file size increases dramatically for each increase in quality. Conversely, the lower you go, the faster the quality degrades, and the file size drops less for each step. Typically, a quality between 80 and 90 is preferable to most people, and the value of 82 that WordPress now uses is based on a study done in 2014 which tested to see how much quality loss was acceptable to the majority. The core developers have stayed well within the .015 DSSIM tolerance, so you typically should have no need to change the quality.

However, some folks don’t care about file size, and would rather have better quality (or they just think 82 is a bit TOO low, since it used to be set at 90). A second problem people run into at this point, is that they think setting it to quality 100, or 12 in Photoshop, will disable compression altogether. That just isn’t true, since JPEG is by definition a lossy format. Every single time you re-export or re-save a JPEG file, you will lose pixels, even at maximum quality. The only mechanism that can reduce file size, and achieve zero pixel loss, is the lossless compression employed by tools like jpegtran or jhead. Since they don’t alter the image itself, the back-end compression is all that gets altered. It’s similar in nature to how lossless PNG compression works. The pixels are all preserved, the tools just look for optimal compression parameters, which takes more time. Camera manufacturers (and most photo editors) default to a level of compression that trades size for speed. They figure people want their images to save faster, rather than achieving maximum compression. In the case of cameras, battery usage is also a concern, since the extra compression would put a higher strain on the processor, and drain the batter much faster. And I think the camera folks probably have it right, people don’t like to wait for their camera to save an image, they want to get on with taking more pictures, especially since storage is so cheap.

The last misconception is that WordPress decreases the quality of images you upload. WordPress does NOT modify your uploaded images by default. It just transfers them straight to the server, unaltered, and uses that unaltered original to create the resized versions. The resizes are where the quality loss is introduced, and this is where the quality level of 82 comes into play. There is a way that your originals CAN be changed though. If you are using a plugin to resize the uploads to a maximum resolution, then the plugin that does the resizing will be using the default quality in WordPress (82) unless you change it.

In EWWW 2.9, I’ve introduced a setting that allows you to modify the default quality of your resizes. You can find it under the Advanced settings, but remember that this does not affect optimization, only the initial resize operation. Optimization is still lossless by default, and uses smart algorithms for lossy modes. The lossy compression is usually able to achieve much better savings, with higher quality than you’ll ever get by adjusting the quality lower than 82. For this reason, I don’t recommend using the new setting to decrease the quality, only for increasing. That said, EWWW is all about flexibility, and if you want to lower it to 10 we won’t stop you, but your eyes might have something to say about that 🙂 Instead, take advantage of the best lossy compression in the industry, and get those images optimized.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.