Override global JPEG quality value based on cookie I am working on a site that has an international audience and that needs to allow users to toggle a "low bandwidth" version. In order to achieve this, I would like to check if a cookie has been set and if so, override the global JPEG quality value from 75% down to, for example, 40%.

How can I override this variable and is this even possible with image caching?
This would need a bunch of image styles, a custom field formatter, a custom module that reads that cookie value, and a speed test of some sort.


You'd need to create image styles for each of the quality tiers that you want. That part can be done with the built-in image styles module.
Then you'd want to create a custom module that:


Detects the speed of the client's connection and sets that cookie. It can simply be JS downloading a 1KB file download whose start and end times are recorded and set on a cookie.
Supplies a custom field formatter to image fields that, instead of making you select a fixed quality, will select the image style and render the image with that image style on-the-fly. As an added bonus, you could allow the formatter to be configurable by exposing a form that allows the selection of which image style to use at certain speeds.
Lastly, detects the cookie that was set earlier and informs the field formatter which image style to use based on the cookie value.



This assumes that all imagery are coming from fields (because of the field formatter). For theme imagery, you'll need to render your images by hand in the same way as above, sans the field formatter.