This red goes to #FG0000: Wide-Gamut Color with <picture> and Cloudinary

Wdd Logo.
May 23, 2017
This red goes to #FG0000: Wide-Gamut Color with <picture> and Cloudinary.
Recently, I had the pleasure of reading Craig Hockenberry’s short, sweet, and informative Making Sense of Color Management. In the book, Craig points out that while new, Hi-DPI screens present us with more resolution than our eyes can actually see, they’re nowhere close to being able to produce all of the colors that we’re capable of perceiving. Excitingly, that’s beginning to change. Various long-stagnant pieces of our graphics stacks are lurching forward into a more-vibrant future. The next frontier in making things look amazing on screens is wide-gamut color.

Wide-gamut Screens

For the last 20 years, the display industry has settled on a limited, standard range of colors, called the sRGB gamut. If the lopsided, chopped-off-rainbow-disc below (technical name: the “1931 CIE Chromaticity Diagram”) represents all of the colors that human eyes can see, the sRGB gamut is circumscribed by the little triangle in the middle. sRGB The latest-generation of displays can produce colors outside of sRGB’s limited range. These screens expand the triangle of possibilities out, to what’s called the P3 gamut: P3_vs_sRGBThe P3 gamut, compared to sRGB. It’s bigger! Triangles are one thing and actual photographs are another—for a sense of what this wider range actually looks like in practice, beg, borrow, or steal a wide-gamut display and go check out Craig’s gorgeous example images, or look at this quick example, from yours truly. Basically, if your subject is really saturated (for example: an incandescent sunrise, or bright-green grass) P3 will let your images pop in new and notable ways. But if your image’s palette is more subdued, sRGB already has you covered and you’ll see no visible difference. So – devices that can display new, more vibrant colors are shipping en masse. How can we take advantage of them, without screwing things up for everybody else?

Wide-gamut Resources

First, we have to produce files that contain these new colors. Generally, you can do this by making sure that: 1) your camera is capturing– 2) your software is editing– and, crucially, 3) that you’re exporting– in a wide gamut (like P3, Adobe RGB, or Adobe ProPhoto). And don’t forget to embed a color profile. For a detailed tutorial on how to do this with Photoshop, buy Craig’s book! If you’ve got a shiny new iPhone, though, you don’t have to worry about minding your Ps and Qs in obscure preference panes. The iPhone 7 captures, processes, and saves photos in the P3 gamut out-of-the-box.

Wide-gamut on the Web

Ok, so let’s say you’ve captured a beautiful sunrise and produced a wide-gamut Jpeg with an embedded profile. Great! How are you going to share that image with the world? Let’s start by marking it up using a single-src <img>: <img src="sunrise-p3.jpg" alt="Oranges and blues" /> In browsers that implement “color management” – browsers that know how to use the image’s embedded profile to map the image’s wide-gamut colors to a device’s particular screen – the sunrise will always look as good as the hardware will allow. It will look good on sRGB-ish screens, and great on wide-gamut displays. But many browsers are not color managed. And in color-unmanaged browsers, the raw color values in our image are painted directly to the screen, without consideration for how the file’s wide profile relates to the display’s limited gamut. This results in a dull image – much worse than if we’d just left well enough alone and exported our image in sRGB: p3_and_sRGB_unmanagedComparison between a vibrant, sRGB sunrise and a a dull, wide-gamut sunrise on a color-unmanaged display In color-dumb browsers, wide-gamut images look worse than their narrow-gamut, sRGB counterparts. What can we do about this sad state of affairs? Unfortunately, there’s no easy way to feature test whether or not a browser is color-managed. But we can ask the browser if a screen’s profile is more sRGB-like or P3-esque, using the brand-new color-gamut media query. If we use this query within a <picture> element, we can make sure that we only send wide-gamut images to wide-gamut screens – and send sRGB images to everybody else:
<picture>
<source media="(color-gamut: p3)" srcset="sunrise-p3.jpg" />
<img src="sunrise-sRGB.jpg" alt="Oranges and blues" />
</picture>
That, my friends, is a color-adaptive responsive image. Neat!

Responsive Color with Cloudinary

Make no bones about it, creating responsive image assets is tedious. Whether you’re rendering multiple resolutions, crops, formats, or, now, color gamuts – the task of generating alternate versions of your assets is ripe for automation. Enter Cloudinary. Cloudinary’s color-smarts are still evolving, but today, the service has two key features:
  1. If an uploaded image has a color profile, Cloudinary preserves it.
  2. Cloudinary can convert any image to sRGB using the cs_srgb transformation.
So, if we generate a wide-gamut original and upload it to Cloudinary, we can deliver it color-adaptively, like this:
<picture>
<source
media="(color-gamut: p3)"
srcset="https://res.cloudinary.com/eric-cloudinary/image/upload/sunrise.jpg" />
<img
src="https://res.cloudinary.com/eric-cloudinary/image/upload/cs_srgb/sunrise.jpg"
alt="Oranges and blues" />
</picture>
This pattern allows us to generate a single, wide-gamut resource, and deliver it in a way that looks great for some, and good for everybody. ✨☺️??✨

Ready for Anything

As screens begin to evolve along this new axis – becoming more colorful – it’s gratifying to see the techniques and toolchains built to cope with the Retina-revolution so ready to tackle a new challenge. On the ever-evolving, always-diversifying web, adapting bitmap images to varied browsing contexts is a general problem, and responsive image markup patterns – paired with a centralized, automated image-processing back-end like Cloudinary – are here to solve it, no matter the particulars. So – armed with P3, <picture>, and Cloudinary’s cs_srgbvoyage forth bravely into a wider world of color. [-- This is a sponsored post on behalf of Cloudinary --]

WDD Staff

WDD staff are proud to be able to bring you this daily blog about web design and development. If there's something you think we should be talking about let us know @DesignerDepot.

Read Next

LimeWire Developer APIs Herald a New Era of AI Integration

Generative AI is a fascinating technology. Far from the design killer some people feared, it is an empowering and…

20 Best New Websites, March 2024

Welcome to our pick of sites for March. This month’s collection tends towards the simple and clean, which goes to show…

Exciting New Tools for Designers, March 2024

The fast-paced world of design never stops turning, and staying ahead of the curve is essential for creatives. As…

Web Tech Trends to Watch in 2024 and Beyond

It hardly seems possible given the radical transformations we’ve seen over the last few decades, but the web design…

6 Best AI Productivity Apps in 2024

There’s no escaping it: if you want to be successful, you need to be productive. The more you work, the more you…

3 Essential Design Trends, February 2024

From atypical typefaces to neutral colors to unusual user patterns, there are plenty of new website design trends to…

Surviving the Leap from College to Real-World Design

So, you’ve finished college and are ready to showcase your design skills to the world. This is a pivotal moment that…

20 Mind-Bending Illusions That Will Make You Question Reality

Mind-bending videos. Divisive Images. Eye-straining visuals. This list of optical illusions has it all. Join us as we…

15 Best New Fonts, February 2024

Welcome to February’s roundup of the best new fonts for designers. This month’s compilation includes some innovative…

The 10 Best WordPress Quiz Plugins in 2024

Whether it’s boosting your organic search visibility or collecting data for targeted email marketing campaigns, a great…

20 Best New Websites, February 2024

It’s almost Valentine’s Day, so this latest collection is a billet-doux celebrating the best of the web this month.

Everything You Need to Know About Image Formats In 2024

Always trying to walk the tightrope between image quality and file size? Looking to branch out from JPGs and PNGs this…