Compressive Images

Posted by Scott on 10/30/2012

Here at Filament Group, we’ve invested a great deal of time thinking about how best to deliver images that look sharp on devices from a low-resolution phone to High-resolution (HD) screens like Apple’s Retina™ or the new Nexus 10, while being as lightweight as possible for performance. In practice, this is more difficult than it may sound, as there is currently no native HTML solution to deliver different versions of an image, so we resort to JavaScript or server-side workarounds to achieve a similar result.

This week we came across an interesting technique. In his article titled Retina Revolution, Daan Jobsis shared the following premise: when considering a jpeg image’s file size, the level of compression makes more of a difference than its physical dimensions. In other words, given two identical images that are displayed at the same size on a website, one can be dramatically smaller than the other in file size if it is both highly compressed and dramatically larger in dimensions than it is displayed.

While we’re not sure it stands to replace the responsive image techniques currently in play, we are very excited about its potential for complementing them. The article discusses the technique’s “retina” implications, though in practice, the approach may have much more potential than differentiating high resolution “retina” (HD) and standard definition (SD) screen density alone.

###An example comparison

Let’s look at an example. Both images below are displayed at 400 pixels width and 300 pixels height.

This first image is saved with those dimensions specifically (it’s displayed at 100% size), with a typical 90% quality jpeg compression from Photoshop. It weighs 95kb.

Full-size sample image

This second image, however, is actually scaled down by the browser. Its natural size is 1024x768px, but its compression was set to 0 (zero!) quality when saved from Photoshop. As a result, it weighs 44kb.

Lightweight, scaled-down sample image

The images look roughly similar in quality, yet the second one is less than half the weight. Since that image is more than twice the resolution of the display size, it also looks sharp on retina screens.


Assuming there aren’t drawbacks we’ve yet to consider (and there usually are), we’re unsure how this affects our current thinking on responsive images.

For one thing, we’re sure that this does not entirely replace the features of the proposed picture element. For example, picture’s ability to deliver different image sources altogether means we can provide different crops of an image depending on the size, and a single image can’t currently do that. In this context, it’s possible that we might use this technique to reduce the size of those sources.

Still, for images that are merely delivered at different sizes without any changes to the crop, this technique could present a much simpler solution.

Regardless, we think it’s a pretty interesting twist. We’d love to hear your thoughts!

Note: Daan has posted a followup article worth reading as well.


<div id="commentNumber1" class="commentEntry">
<p>Love the work you guys are doing, and I’ll definitely try to use this in my next project.

A potential drawback i see is to do with how jpeg handles compression. In the image you’ve provided above, the aspects of the image that get the most improvement are around the edge of the cliff face in the foreground. That area seems to be much more defined in the high-resolution version than in the normal version.

However, if you look at the clouds on the top left, the lack of quality really shows through.

Artefacts in jpg compression tend to show through more in flat colours and sharp lines, so this technique should be used for photography that doesn’t have much of that. (no flat surfaces like exposed skin, no sharp lines like typography)

	<p class="posted"><a href="#commentNumber1">Comment</a> by

Clark Pan on 10/30  at  05:47 PM

<div id="commentNumber2" class="commentEntry">
<p>(I think the correct reference for this technique is Thomas Fuchs’ book “Retinafy your web sites &amp; apps”. He talks about this for some time now.)

And one drawback I think nobody is talking about is memory usage. Despite being better compressed and having a smaller file size, the retina version uses 4x the memory needed for the smaller image. That is because all images are bitmapped when expanded. It can be a problem if we are talking about simpler devices like mobile phones.

	<p class="posted"><a href="#commentNumber2">Comment</a> by

Sérgio Lopes on 10/30  at  06:16 PM

<div id="commentNumber3" class="commentEntry fg">
<p>@Clark: great points, thanks for chiming in.

@Sergio: Nice catch. We haven’t read Thomas’ book but it’s nice to know the particular technique has been mentioned in other places. Daan’s was the first we came across on the topic.

Good points on memory usage, too. We assumed there would be some drawbacks to consider. Definitely worth testing!

	<p class="posted"><a href="#commentNumber3">Comment</a> by

Scott (Filament) on 10/30  at  06:26 PM

<div id="commentNumber4" class="commentEntry">
<p>great article(s), as always

i think the main benefit of this technique is you get a simpler picture element, with less sources (you can remove @2x). there is still urgent need of a picture element imho, for two reasons at least:

1. editorial crop depending on zoom/context
2. vertical rhythm depending on crops, scaling is not enough precise

btw: i sent a PR on your picturefill, maybe very opinionated tho :D

	<p class="posted"><a href="#commentNumber4">Comment</a> by

Sergi on 10/30  at  06:31 PM

<div id="commentNumber5" class="commentEntry">
<p>My question about this technique for use in a responsive context is that the image would begin to degrade as the device “scales up”, wouldn’t it? I see it being useful in the retnification (that’s a word, right?) scenario—but less helpful in a responsive context as the display of the image gets closer to reaching its actual dimensions.

Am I understanding that correctly?

	<p class="posted"><a href="#commentNumber5">Comment</a> by

Bridget Stewart on 10/30  at  07:43 PM

<div id="commentNumber6" class="commentEntry">
<p>Interesting idea though I guess it only works with jpg photos.

How does it work with images with solid colors and sharp edges (e.g. graphics)?

A combination of this technique and use of SVG would perhaps be a solution.

	<p class="posted"><a href="#commentNumber6">Comment</a> by

Jakob Damgaard on 10/31  at  02:53 AM

<div id="commentNumber7" class="commentEntry">
<p>I am a bit worried about this technique. Of course it is easier for developers to serve such images but on the other hand these images take more resources of the (especially mobile browser).

I tested this on a full-background page recently (2048px*1536px as img-size) and found out that even on a Desktop UA this technique slows down the whole window and results in a bad user experience. For example scrolling isn’t smooth anymore.
This behavior can be avoided on some (not all!) mobile devices using the img{ transform: translateY(0); } CSS3 value. This triggers hardware acceleration.
Overall this means it takes more resources from a mobile device and can result in a crash on mobile devices, too.

The other problem is we have a limit of maximum pixels on an image in mobile OS. That means for iOS4 4MP and for iOS5 5MP.  That might seem much for the first thought but it really isn’t. If you have a panorama image that is super easy to reach when optimizing for retina displays (e.g. iPad3/4: 2048px*1536px). And this is nowadays not uncommon as a resolution. Notebooks even have larger displays right now.

So it can be a somehow useful technique but also is very problematic if you don’t really know what you do. Using the technique with a responsive images-solution it would work good for most displays.1

	<p class="posted"><a href="#commentNumber7">Comment</a> by

Anselm on 10/31  at  03:04 AM

<div id="commentNumber8" class="commentEntry">
<p>would be nice to know how far one could decrease the jpeg compression until hit the filesize of the one with the lower resolution (and how the image would look like with that compression)

	<p class="posted"><a href="#commentNumber8">Comment</a> by

Markus on 10/31  at  03:07 AM

<div id="commentNumber9" class="commentEntry">
<p>@Markus: As you can see, JPEG compression is at 0% quality and the file is sometimes even smaller than the standard resolution. More examples are on the original blog post here: <a href="" rel="nofollow"></a>

	<p class="posted"><a href="#commentNumber9">Comment</a> by

Anselm on 10/31  at  03:08 AM

<div id="commentNumber10" class="commentEntry">
<p>@Anselm Thanks for the hint.

Any chance to measure the time the browser taktes to re-scale the fullsize image?

	<p class="posted"><a href="#commentNumber10">Comment</a> by

Markus on 10/31  at  03:17 AM

<div id="commentNumber11" class="commentEntry">
<p>I’m always excited about experimenting and this was insightful. I feel that the outcomes of this experiment are a bit exaggerated though.

For example, when is a 90% quality jpeg compression typical when the presets are Medium (50), High (60) and Very High (80) and Maximum (100)? I almost always use medium or high depending on what I can get away with and still looks good.

I tried out your technique on a 400px photo at 90%, 50% and 800px photo at 0% (double size) and the 50% compression looks much better than the 0% jpg and is 2kb smaller.

The 800px @ 10% quality starts looking pretty comprable to the 400px@50% but is now bigger in size.

I know this is all experimenting and just thought I’d share some of my results as well.  The idea of “retina graphics at even smaller file sizes” still remains a dream :)

	<p class="posted"><a href="#commentNumber11">Comment</a> by

Taylor McKnight on 10/31  at  04:12 AM

<div id="commentNumber12" class="commentEntry fg">
<p>Thanks for all the comments everyone. Like any technique, we all need to find the sweet spot for when to use this. A few things are clear:

- Since this is based on JPEG compression, this is only appropriate for photographic style content. Line art with flat colors should be compressed as a GIF, PNG-8, or ideally SVG. See our article on GruntIcon as a possible technique for using SVGs today with a PBG fallback.

- We need to strike a balance between image quality and memory use and that will take testing and experience to hammer out some guidelines. It’s clear that serving retina quality background images at 2048px*1536px like @Anselm tested is probably not a good idea because that could cause many devices to grind to a halt or even crash. This technique is an interesting way to reduce bandwidth for larger images, but doesn’t change the basic rules for how images work in a browser so we need to be practical on sizes. Unfortunately, a lot of the HD devices out there are phones and tablets and they have very little memory.

- The idea is to test various things and see what works, we don’t have the answers right now. For example, we might be able to serve an image that is 1.5x or 1.7x the standard definition size (instead of a full 2x) and increase the compression from 0 to 20 or so. This might strike a better balance between file size, quality, resolution and memory use.  Demo:

If I were to choose today between doing nothing for retina by just serving SD images with normal compression levels and tinkering with this technique, I’d do the latter. It will look better on retina and be the same or less file size.

Keep testing and report back with demo pages, this is an interesting conversation!

	<p class="posted"><a href="#commentNumber12">Comment</a> by

Todd (Filament) on 10/31  at  09:58 AM

<div id="commentNumber13" class="commentEntry">
<p>I think we are losing focus on the main purpose of the web: serving content.

I’m sure that doing this “scale-down thingy” solves a lot of headaches, but we are serving a crappy image.
Now when our visitor decides to save the image, or open it on a new window, or anything not involving the CSS scalation, he’s going to get a “double sized-artifacted-blurred” image, and I think this totally sucks.

Despite this “little” thing, I love the approach to solve the problem ;)

	<p class="posted"><a href="#commentNumber13">Comment</a> by

Harold Dennison on 10/31  at  09:59 AM

<div id="commentNumber14" class="commentEntry">
<p>Creative technique but I think lowsrc solves the problem more eloquently. Create two images,  one high res, one low res and both at 90% quality. It solves the page load time, high res display problem and some of the other issues mentioned in this thread. Old school but still works in all browsers and is part of the spec.

	<p class="posted"><a href="#commentNumber14">Comment</a> by

Richard Ayotte on 11/01  at  07:22 AM

<div id="commentNumber15" class="commentEntry">
<p>Clever, but as several have pointed out already memory usage is the elephant in the room.

In my forays into mobile web dev the main problems I’ve come up against have been the low memory ceilings of mobile browser web pages.

	<p class="posted"><a href="#commentNumber15">Comment</a> by

pete_b on 11/01  at  11:00 AM

<div id="commentNumber16" class="commentEntry">
<p>It’s quite fun to watch your guys work on this problem and to see the discoveries along the way. Even better to see the community feedback!

	<p class="posted"><a href="#commentNumber16">Comment</a> by

Joseph R. B. Taylor on 11/01  at  11:24 AM

<div id="commentNumber17" class="commentEntry">
<p>Yeah, this is something I discovered quite a while ago when the retina iPads first came out, and I made a nice little web page utility to test out different compression settings on a handful of test files. (Though it’s optimized in size for the iPad, it would work on a Retina Mac as well.)   <a href="" rel="nofollow"></a>

The one thing I’m cautious about is the client-side memory to handle the large image. I remember hearing some warning from Apple about not serving up a gigantic-dimension image and expect a lightweight client to have the chops to handle it.  So maybe it wouldn’t be a good idea to put a whole bunch of large (but compressed) photos all on the same page. Then again, I suppose testing on various clients would be in order just

	<p class="posted"><a href="#commentNumber17">Comment</a> by

Dan Wood on 11/01  at  12:56 PM

<div id="commentNumber18" class="commentEntry">
<p>First of all, the 2nd image really looks a lot worst than the first.

Secondly; when saving images, 90% quality is usually way to high. Setting it to 80% would make the file quite a bit smaller.

But I like the general idea of setting the quality somewhat lower on the retina version of an image.

	<p class="posted"><a href="#commentNumber18">Comment</a> by

Gerben on 11/01  at  01:33 PM

<div id="commentNumber19" class="commentEntry">
<p>Very interesting technique. It looks like the highly compressed HD images are more often than not, smaller than SD images with medium to low compression.

I’d be really curious to see if anyone has some numbers on the memory usage when using these highly compressed HD images. It seems like something to be cautious of, though I’d love to see some hard data on the memory usage.

	<p class="posted"><a href="#commentNumber19">Comment</a> by

Brett Jankord on 11/01  at  01:34 PM

<div id="commentNumber20" class="commentEntry">
<p>@Gerben If you check out Dan Wood’s website, <a href="" rel="nofollow"></a> it looks like HD images saved at 5% quality were pretty close to SD saved at 60% quality.

	<p class="posted"><a href="#commentNumber20">Comment</a> by

Brett Jankord on 11/01  at  01:37 PM

<div id="commentNumber21" class="commentEntry">
<p>My concern is that what about when a viewer wants to save of download the compressed image? Wouldn’t the saved image appear to be of that poorer quality?

	<p class="posted"><a href="#commentNumber21">Comment</a> by

Eric Lakatos on 11/01  at  09:06 PM

<div id="commentNumber22" class="commentEntry">
<p>This is a load of baloney.

As others have said, I’m not sure who would ever apply 90% compression to an image intended for web –– 50-70% is more realistic. At 50%, the smaller image will be around 2/3 the file size of the larger, hyper-lossy image. So that comparison doesn’t hold up.

More egregiously, though, is the 0% compression on the larger one. It looks like absolute crap to me. Not to mention that it will gobble up precious memory on mobile devices, rendering the page needlessly slow and unresponsive.

Re-scaling images (and text for that matter) is best avoided at all costs, whether on desktop or mobile, and you should ask yourself whether your time (in creating a robust solution for high-density screens) is more important than the user experience.

I would argue that the latter is more important, but that’s a matter of personal preference.

	<p class="posted"><a href="#commentNumber22">Comment</a> by

Derryl Carter on 11/02  at  12:29 AM

<div id="commentNumber23" class="commentEntry">
<p>May cause aliasing with some images on non-webkit browsers.

Example :

	<p class="posted"><a href="#commentNumber23">Comment</a> by

Franck Bossy on 11/02  at  05:04 AM

<div id="commentNumber24" class="commentEntry fg">
<p>Thanks all, great conversation!

Re: quality, we weren’t trying to “stack the deck” by using too low a compression to bloat the file size. The right level of compression for the normal quality image that we use as a comparison depends on the image and your opinion on acceptable artifacts. I personally find that 70-80% quality looks good to me for standard JEPG compression, below that looks too compressed for my tastes, let alone 50%.

I had used Apple’s real imagery in my jsbin demo because that is a real -world example of what a detail-oriented company considers correct compression for both sizes. Note that I had linked to the wrong file for Apple’s retina image in my previous comment’s demo. See for a corrected demo.

As Brett mentioned, this is a really cool tool that lets you try different photos and quality levels. This is best way to get a handle on how this technique works. Wish we had seen this earlier!

Franck’s comment on the quality when re-sized varies widely across browsers and devices is very interesting (we thought this was mainly a very old IE and BB thing). Has anyone done a thorough test across all these to see which re-size smoothly and which are jaggy?If not, we can dig in.

The comments on the quality when viewed at full size are interesting since that’s not the main purpose of the technique, but worth considering. Perhaps this is a better technique for content imagery, but wouldn’t be ideal for a photo sharing site where the images are frequently downloaded and viewed at full size. You could also use these compressive images as the preview then link to the ultra high quality image for downloading.

Lastly, a few folks mentioned that Thomas Fuchs suggested a similar technique in his retina e-book a few months ago. If you have a link to public info we can share from Thomas, please post that here. Hat tip nevertheless.

	<p class="posted"><a href="#commentNumber24">Comment</a> by

Todd (Filament) on 11/02  at  11:09 AM

<div id="commentNumber25" class="commentEntry">
<p>Not sure who Brett is, but I was the one who mentioned my <a href="" rel="nofollow"></a> tool that I had created back in March.&nbsp; Anyhow, I haven’t touched it in a while, but if people have any requests on how I can improve the page, please let me know.&nbsp; (I don’t foresee it being able to process user-uploaded images though, since that would mean putting some actual image processing on the server.&nbsp; It’s just displaying images that have been created in advance on my Mac.)

More info about the tool by clicking/touching “About This” on the page.

- Dan

	<p class="posted"><a href="#commentNumber25">Comment</a> by

Dan Wood on 11/02  at  11:38 AM

<div id="commentNumber26" class="commentEntry">
<p>It’s a similar effect (if you ask me) when you see billboard signs. From a distance they look normal, but up close they look horrible.

Interesting thought.

	<p class="posted"><a href="#commentNumber26">Comment</a> by

Marco Berrocal on 11/03  at  02:30 PM

<div id="commentNumber27" class="commentEntry">
<p>Looks like a very clever technique. The Filament guys are always good for some innovation. I’m gonna try this out in one of my next projects and see what it’s good for.

	<p class="posted"><a href="#commentNumber27">Comment</a> by

Marcel on 11/04  at  01:34 PM

<div id="commentNumber28" class="commentEntry">
<p>Was thinking more about the memory concern I’ve seen people post on here and on twitter about re-sizing the HD image in the browser to half size.

Isn’t this the way its done with HD images that are used as backgrounds with CSS for retina displays. I don’t think I’ve seen people talk about memory issues when HD images were re-sized with the CSS background-size property.

I assume there is some memory hit with this technique, but I don’t know if it’s as bad as people are making it out to be. Would love to see some numbers on the memory usage with this technique.

	<p class="posted"><a href="#commentNumber28">Comment</a> by

Brett Jankord on 11/07  at  05:56 PM