Requests for comment/Reducing image quality for mobile

Many mobile devices with low bandwidth or small screen/slow processor could benefit from showing JPEG images with reduced quality. Such images would transmit much faster and may require less memory to process.

Extend image URL syntax

 * This part has been implemented as patch 119661 and needs a review

The production backend generates requested image if file is missing (404). The url is parsed with regex to extract the desired image width. In order to pass quality reduction parameter, we need an extra value "-qNNN". The value is optional, thus keeping the existing image cache intact.

 //upload.wikimedia.org/wikipedia/commons/thumb/3/33/image.jpg/100px-q30-image.jpg  

This exact approach has already been used for SVG's "language" parameter and for DjVu's "page" parameter.

Quality parameter in Wiki markup

 * There has been some objections to this section, so it might need to be either reworked or removed

Add a "quality" parameter to the image link wiki markup to specify desired quality reduction. Above would render image.jpg with image quality set to 30% and width scaled to 100px. This parameter might be used by various template authors to substantially reduce thumbnail file size.

Technical details
There are currently several workflows for image link parsing, assuming the above wiki markup and generated HTML &lt;img src=".../image.jpg/100px-q30-image.jpg" />:
 * 404 enabled : markup &rarr; HTML &rarr; browser requests image &rarr; image is 404 and rendered on the fly using URL as parameters
 * 404 disabled : markup &rarr; HTML & image file is created based on markup params &rarr; browser requests existing image
 * remote repo : markup &rarr; server calls remote repo via API &rarr; (TBD - still investigating)

Mobile would not want to alter parser's output, as that would fragment parser cache varied on the type of the useragent. In order for mobile or zero to change quality, they can change image URLs via javascript or DOM post-processing, which only only work on 404-enabled site (WMF sites), but will not work on simple installations where 404 is not intercepted. I haven't figured a simple way to solve it, nor am I certain that it needs solving.

Proposal - Zero
Most of Zero network users operate older devices, frequently using slower networks. For Zero users, we propose server DOM rewrite (already being done for external links and some images). The rewrite would remove the srcset img attribute and change the image src from the default .../image.jpg &rArr;  .../image.jpg/q30-image.jpg. All non-js devices would keep using low quality images, while smart phones would use JavaScript to convert q30 images back to default based on locally set user preferences, carrier settings and network quality (TBD). This JavaScript should be done before the HTML is fully loaded as to prevent downloading of both the low and high quality images.

If Zero replaces all images for all pages except File: namespace, we are theoretically looking at creating a copy of every image used. Yet, please keep in mind that most images used on Wiki pages have been significantly scaled down from the original (images tend to be used in smaller frames), and reducing their quality to 30 should make file size even smaller - by my random sampling of several wiki images - at least 30-40% of the original size. The images tend to be 5-10KB, which is 100-200GB absolute maximum if every file on commons (20.5 millions) are actually converted.
 * Usage Assessment