In part 1 of this series we learned how to manipulate an image once we had uploaded it into the dynamic image server. In part 2, we will cover Named Operations, which allow us to add several filters without having mile long URLs.

We will now go into converting those long URLs to something more manageable while still retaining the simplicity of the filters discussed in part 1.

What is a named operation? To start we will setup a mix of filters that will build from our exercise in Part 1 and we'll add more effects like resize, change color and a gaussian blur. Once we put all of these filters together we end up with a very long URL.

This is the perfect time for our named operation to save the day! A named operation is simply a bean in the application context that contains all of the filters and values you want to apply. By creating a named operation called, for example, smallWithBlur we can write a URL that looks like this:

Using named operations we can create a very complex mix of filters while keeping the URL clean with an easy to remember name to append. Instead of having to edit each image independently, one would simply have to add ?smallWithBlur to the URLs and have the images all look the same.

Creating a named operation Broadleaf Commerce allows the use of named operations through the use of Spring's application context configuration.

We will create a bean in the application context. Let's see what the smallWithBlur would look like to get this image:

Solr facet

You'll recognize these are the same parameters from the long link above, but when we do it like this, it allows us to easily reproduce without having to copy/paste or rewrite the same URL over and over.

One thing I would recommend is using the link method to tweak your filter until you get it right since it allows for immediate results. Using the application context is powerful, but the drawback would be having to restart your application after any change.

A bean within a bean There is no limit to the how many named operations you can add and can even be nested by setting the named operation as you would one of the default filters. All that is needed is to add an additional entry to the blStaticMapNamedOperationComponent bean.

Let's add something more to smallWithBlur. We'll call the new filter smallWithBlurAndBW since it will include .smallWithBlur. alongside a change in Hue and Saturation to get back our winter sun from part 1.

Solr facet

The advantage to doing this is forming a hierarchy in our filters. If we later decide that we want to change the resizing, we simply go back to smallWithBlur and change the resizing here. The change would then cascade down to smallWithBlurAndBW making it easy to maintain.

And best of all are our links:

This concludes our short series on the dynamic asset server. For detailed instructions on how to create your own named operation and how to use the asset server you can go to our docs: