Practical Gradient Map Use Case

Screen Shot 2013-08-13 at 5.51.19 PM

I’ve been writing a few posts about the new gradientmaps.js library, and it occurred to me that gradient maps are a little hard to get your head around.  How would you use them in a real-world scenario?  From a pure creativity standpoint, they’re a no-brainer.  But are there any practical use cases?

Here’s a thought.  Say you’re selling shirts on your website.  You’re able to print the shirts in a myriad of colors and want to let the consumer pick the color they want.  In order to implement this, you could have an image for every possible color, or you could do the following (only works in Chrome & Firefox at present, sorry):

Check out this Pen!

In the above example, when you click on the color button and select a color, that new color is used as the right edge of a color gradient which starts with black.  So, if you choose red, the color gradient will go from black to red.  The image of the shirt you see has a transparent background.  And, if you’ll notice if you look at the JS tab, the start of the gradient is actually transparent itself “rgba(0, 0, 0, 0)”.  This is so we don’t recolor the background itself.

The resulting gradient is then applied to the image using:

GradientMaps.applyGradientMap($('img').get(0), gradient);

gradientmaps.js makes use of SVG filters being applied to HTML content.  At present that is only supported on Chrome and Firefox.

Pretty easy, and pretty useful. Play around with it and let me know what you think.

Implementing the Duotone Filter with an SVG Filter

Screen Shot 2013-08-12 at 1.29.36 PM

In a recent post I described a duotone CSS Custom Filter I had built that allowed you to take a black and white image, and remap the black and white colors to two other specified colors.  Say you have a t-shirt website.  You could provide a single black and white image, and users could choose the color they want.

In the original implementation I used CSS Custom Filters, which are a little overkill for this use, and they are currently only supported on Chrome.  Here we’re going to do the same thing, using an SVG Filter.  SVG Filters are currently supported on both Chrome and Firefox and stand a much better chance of being implemented in other browsers sooner rather than later.

In particular, we’re going to use the ComponentTransfer filter primitive, described in more detail in this post.

Let’s take a look at the following SVG implementation (best viewed on Chrome and/or Firefox):

Check out this Pen!

When you click on either the black or white color remapping buttons, JavaScript is executed which recalculates the transfer functions for the feComponentTransfer filter primitives for each color channel.

In the following demo:

Check out this Pen!

We don’t use any JavaScript.  Instead, we’re using the SVG animate primitive to animate the table values of each transfer function (feFuncR, feFuncG, feFuncB).

For both of these examples, click on the HTML, CSS and JS tabs to see what’s going on and let me know if you have any questions.

As you can see, SVG filters are extremely powerful and worth learning more about.  Using them to manipulate HTML content is currently only supported on Chrome and Firefox but it looks very promising that they’ll be supported on all browsers before too long.

Announcing gradientmaps.js

gmcover

gmcover

I’ve just released gradientmaps.js on Github. You can use this library to apply gradient maps to any HTML content using SVG filters. You can find all the details on the Adobe Web Platform team blog:

http://blogs.adobe.com/webplatform/2013/08/06/gradientmaps-js-gradient-maps-for-html/

The library makes use of SVG filters. As indicated on this table of browser support for CSS graphics, applying SVG filters to HTML content is currently supported only on Chrome and Firefox at present.

Check it out, it’s a ton o’ fun.

Fun with SVG Filters

Screen Shot 2013-07-13 at 12.39.56 AM

I’ve been playing around with SVG Filters lately, and let me tell you, I’ve been having a ton of fun.  The best part is, you don’t have to know a lot about SVG here.  The filters, defined in embedded SVG can be applied to your HTML content with CSS.  Once you figure out what filters are available, and how to configure them, it’s really straightforward. Continue reading

Duotone Custom Filter

Screen Shot 2013-05-30 at 5.09.08 PM

Say you have a black & white image and want to display it in many different 2-color schemes.

thief_bwthief_red_yellowthief_blue_pink

You have a few options here.  You could draw the image in a canvas and then use JavaScript to manipulate each pixel.  Or you could in theory convert your black & white image to SVG and then use CSS to manipulate the colors.  That’s probably a pretty decent solution.

Or you could use the new duotone CSS custom filter I’ve built.  You can find the source for the new filter on Github here. Continue reading

Photoshop Layer Mask Implemented with CSS Custom Filters

Screen Shot 2013-05-28 at 3.24.45 PM

My last post talked about how you can create a Photoshop-like soft blur effect with built-in filters.  As I started reading more about how you would actually create that soft blur effect in Photoshop though, I realized that often you don’t want the soft blur to apply to people’s faces.  You want to apply a layer mask which essentially punches through the soft blur around the central subject’s face to reveal the crisp underlying photo on the bottom layer. Continue reading

Creating a Soft Blur Effect with CSS Filters

Screen Shot 2013-05-17 at 10.09.17 PM

CSS Filters can be added to any element on your Web page to create some very nice effects.  You can even add multiple filters to a given element to create some interesting combined effects.   Continue reading

It’s Curtains for You!

Screen Shot 2012-10-09 at 2.18.55 PM

I recently went over to the cnet.com site and was confronted with an ad that really surprised me.  The whole home page itself became a set of curtains that parted to reveal an ad from IBM.  The texture of the curtains themselves was the home page.  Of course, this was faked out with Flash.  If you look carefully the curtain texture isn’t exactly what was on the page, but it’s close enough that you don’t really notice. But then I thought, I bet I could do that easily with CSS Shaders, and with the actual content as texture to boot. Continue reading

CSS FilterLab Detailed Walkthrough

Screen Shot 2012-10-02 at 12.43.16 AM

I’ve created a video below as a detailed walkthrough of the Adobe CSS FilterLab, from installation, to configuring & developing custom shaders, to collaborating with others on filter development. Before FilterLab, I used to describe custom shader development as essentially ‘programming in the dark’. No debug statements, no tracing, no nothing. Now you can visually interact with your shader and see realtime errors.  That’s a huge leap forward.

If you have any interest in CSS Custom Filters, using or developing them, I couldn’t recommend FilterLab more. Continue reading

Reveal.js with CSS Custom Filters

revealshaderlogo

With reveal.js you can create fantastic looking presentations that run in your browser, driven purely with HTML/CSS/JS.  Since you have full control over which browser you use when giving your own presentation, it’s not unreasonable at all to make use of some newer browser features that do not have full cross-browser support yet.

With that in mind, I created a reveal.js presentation that uses CSS Custom Filters to achieve some very compelling transitions. Continue reading