Have you ever struggled to keep your assets and any information you have about them organized? Often times we find ourselves flipping between databases, marketing releases, and the assets themselves. Trying to stay organized and trying to remember when one thing changes to update everything else.
Cloudinary just made this process a whole lot easier. Instead of having to swap out assets when pricing, availability, dates, quantity, or anything else changes, you can just reference your asset's metadata and the changes are made automatically.
Referencing your asset's structured metadata field in your transformation can be performed via the standard URL transformation API or via one of our SDKs helper functions by utilizing user-defined variables.
Let's take a look at a new asset that you'd like to reference its structured metadata in your transformation. Eventually, I want to add the text in my metadata fields as text layers to my asset.
https://res.cloudinary.com/testy1/image/upload/shoes_vq5e2g.png
Step one will be to create a few structured metadata fields. These can be created, updated, and deleted either via the UI or the Metadata API.
For this example, I am creating three structured metadata fields; price, description, and stock number.
The second step is to add metadata value specifics of this asset via the UI or API.
I'm ready to build my URL "on the fly" transformation. First I declare my user-defined variables so that I can reference them later in my transformation. The basic structure of defining metadata as a variable in your transformation will be `${variable_name}_md:!{metadata_field}!` Afterwards I'll incorporate these variables in a few text layers overlayed on my asset.
Let's breakdown each section of my final URL:
- https://res.cloudinary.com/testy1/image/upload/
The delivery domain with my cloud (testy1), the asset type (image), and the delivery type (upload)
- $descriptionvar_md:!description/$stock_md:!stock!/$price_md:!price!
I reference my metadata field 'description' and add a user-defined variable I can reference later with the name 'desc'. I also add variables for a few other metadata fields I'd like to reference.
- l_text:verdana_15:$(desc),g_north_west,c_fit,w_160,co_white,b_gray
This is where I actually use the variable `desc` that we defined previously. I add a text layer and use the variable for the text content. I then place it with a gravity transformation, crop the layer, and define its width, background color, and font color. I then add layers for price and stock variables as well.
- shoes_vq5e2g.png
Finally, I specify the public_id of the asset that holds all of my metadata.
After all that hard work we are left with the resulting URL:
https://res.cloudinary.com/testy1/image/upload/$desc_md:!description!/$stock_md:!stock!/$price_md:!price!/l_text:verdana_15:$(desc),g_north_west,c_fit,w_160,co_white,b_gray/l_text:verdana_60:$(price),g_north_east,co_red/l_text:verdana_10:Only%20$(stock)%20left%20in%20stock,g_south_east/shoes_vq5e2g.png
The great thing about using structured metadata instead of just typing your text into the layer is that you can update the data automatically. You can also create if statements to programmatically change your asset based on your metadata fields.
So let's say you want to change the image automatically if the stock drops below a certain amount. If we add an if statement to our URL, once the stock drops below a certain amount, your assets will update automatically:
if_$stock_lt_1/l_text:verdana_100:SOLD%20OUT,co_red/if_end
https://res.cloudinary.com/testy1/image/upload/$desc_md:!description!/$stock_md:!stock!/$price_md:!price!/l_text:verdana_15:$(desc),g_north_west,c_fit,w_160,b_lightblue/l_text:verdana_60:$(price),g_north_east,co_red/l_text:verdana_10:$(stock)%20left%20in%20stock,g_south_east/if_$stock_lt_1/l_text:verdana_100:SOLD%20OUT,co_red/if_end/shoes_vq5e2g.png
Using structured metadata fields in your transformations might seem complicated at first but with a little practice, you can create amazing programmatic assets with reduced URL length. There is no limit to what you can accomplish.
Now that you've learned how to reference your asset's structured metadata field in your transformation you can quickly update your assets automatically by combining them with conditional transformations or simply shorten your URLs. You could even use Named Transformations to implement your new transformation at scale.
Read more about:
Conditional Transformations
Transformation API
Metadata API
User Defined Variables
Comments
0 comments
Please sign in to leave a comment.