Cloudinary Blog

Image Opacity Transformation and Dynamic Watermark Generation

By Nadav Soferman
Modifying an image opacity so the image is semi-transparent is a common requirement when implementing modern graphics design. Reducing image opacity allows background images to feel less dominant. Reducing opacity also allows layering of multiple images one on top of the other, an important step when adding watermarks, badges and textual overlays to images.
 
Modern web browsers support opacity transformation via CSS directives. This however does not solve the problem completely. Watermarks need to be embedded as part of the original image and can't be added on the client's side. In addition, transforming the opacity of the image itself allows for a consistent view across all your service's mediums - website, mobile application, emails (notifications) and PDFs (reports). Emails in particular do not support many of the modern CSS directives.
 
In this blog post we wanted to show how you can use Cloudinary's cloud-based image transformations to easily transform the opacity of images and how to use this technique to add watermarks to images.
 

Dynamically changing Image Opacity

Let's look at the following image the was uploaded to the cloud using the 'mountain' public ID.
 
 
You might want to use an image like the one above as a background image for a section of your web or mobile application. Simply set the 'opacity' parameter (or 'o' for URLs) to the desired percentage and Cloudinary will automatically modify the opacity of the image on-the-fly. As always, the resulting image is stored persistently in the cloud  and delivered optimized and cached to your worldwide users through a fast CDN.
 
The following example reduced the mountain image opacity to 20%. Now you can safely place text and other graphical elements above this image.
 
 
 
Below are examples of generating a transformation URL with modified opacity using our client libraries for Rails, PHP, Django and Node.js
Copy to clipboard
<%= cl_image_tag("mountain.jpg", :opacity => 20) %>
Copy to clipboard
<?php echo cl_image_tag("mountain.jpg", array("opacity" => 20)) ?>
Copy to clipboard
import cloudinary
img = cloudinary.CloudinaryImage("mountain.jpg")
img.image(opacity=20)
Copy to clipboard
cloudinary.image("mountain.jpg", { opacity: 20 });
 

Grayed-out Logos

Another common graphic design practice is to display a list of logos of customers and partners in your web site. Instead of the original, colorful logos, many web designers prefer to display semi-transparent grayed versions of these logos so they don't take attention from the website's messaging. 
 
With Cloudinary you can dynamically gray out images, and easily modify them in case your graphic designer has a change of heart.
 
In the following example, we've uploaded multiple logos to Cloudinary. We've went further and used Cloudinary's sprite-generation capabilities to merge these logos into a single sprite image for better performance:
 
 
 
By simply setting the 'effect' parameter (or 'e' for URLs) to 'grayscale' and setting the 'opacity' parameter ('o' for URLs), Cloudinary generates a semi-transparent gray-scale version of the logos for embedding in your website:
 

 

Generating Watermarks

In a previous blog post, we've shown how you can easily add overlays to images. Such overlays could be used to add watermarks to images using a previously uploaded semi-transparent PNG image of such watermark. With the new opacity transformation transformation, you can file upload your non-transparent watermark image and transform its opacity dynamically to make it semi-transparent, ready for adding as a watermark overlay.
 
The following example adds the previously uploaded image 'cloudinary_icon' as a 200 pixels wide overlay above the mountain image:
 
 
 
Now, by setting opacity to 40%, the overlay becomes semi transparent:
 
 
 
 
 
You can also apply an effect or filter on the overlay. In the following example we've increased the brightness of the overlay to make it white and reduced opacity to 30%:
 
 
 
The code samples below detail how to build the same URL in Ruby, PHP, Django and Node.js:
 
Copy to clipboard
<%= cl_image_tag("mountain.jpg", :opacity => 30, :effect => "brightness:20", 
                  :width => 200, :overlay => "cloudinary_icon") %>
Copy to clipboard
<?php echo cl_image_tag("mountain.jpg", array("opacity" => 30, 
  "effect" => "brightness:20", "width" => 200, "overlay" => "cloudinary_icon")) ?>
Copy to clipboard
import cloudinary
img = cloudinary.CloudinaryImage("mountain.jpg")
img.image(opacity=30, effect="brightness:20", width=200, overlay="cloudinary_icon")
Copy to clipboard
cloudinary.image("mountain.jpg", 
  { opacity: 30, effect: "brightness:20", width: 200, overlay: "cloudinary_icon" });
 

Summary

Dynamic opacity transformation and watermark generation are some of the newest Cloudinary capabilities in your image transformation tool-belt. These capabilities further simplify your web and mobile applications tedious image management tasks. 
 
With a simple URL (or one line of code) you can generate images that match your ever evolving graphic requirements and deliver them quickly to your users. You don't have to deal with complex non-standard CSS directives and you don't have to use over-qualified graphical software like Photoshop to generate images in your desired color balance and opacity.
 
Please share your thoughts and let us know how we can further improve Cloudinary's growing feature set.

Recent Blog Posts

Our $2B Valuation

By
Blackstone Growth Invests in Cloudinary

When we started our journey in 2012, we were looking to improve our lives as developers by making it easier for us to handle the arduous tasks of handling images and videos in our code. That initial line of developer code has evolved into a full suite of media experience solutions driven by a mission that gradually revealed itself over the course of the past 10 years: help companies unleash the full potential of their media to create the most engaging visual experiences.

Read more
Direct-to-Consumer E-Commerce Requires Compelling Visual Experiences

When brands like you adopt a direct–to-consumer (DTC) e-commerce approach with no involvement of retailers or marketplaces, you gain direct and timely insight into evolving shopping behaviors. Accordingly, you can accommodate shoppers’ preferences by continually adjusting your product offering and interspersing the shopping journey with moments of excitement and intrigue. Opportunities abound for you to cultivate engaging customer relationships.

Read more
Automatically Translating Videos for an International Audience

No matter your business focus—public service, B2B integration, recruitment—multimedia, in particular video, is remarkably effective in communicating with the audience. Before, making video accessible to diverse viewers involved tasks galore, such as eliciting the service of production studios to manually dub, transcribe, and add subtitles. Those operations were costly and slow, especially for globally destined content.

Read more
Cloudinary Helps Minted Manage Its Image-Generation Pipeline at Scale

Shoppers return time and again to Minted’s global online community of independent artists and designers because they know they can count on unique, statement-making products of the highest quality there. Concurrently, the visual imagery on Minted.com must do justice to the designs into which the creators have poured their hearts and souls. For Minted’s VP of Engineering David Lien, “Because we are a premium brand, we need to ensure that every single one of our product images matches the selected configuration exactly. For example, if you pick an 18x24 art print on blue canvas, we will show that exact combination on the hero images in the PDF.”

Read more
Highlights on ImageCon 2021 and a Preview of ImageCon 2022

New year, same trend! Visual media will continue to play a monumental role in driving online conversions. To keep up with visual-experience trends and best practices, Cloudinary holds an annual conference called ImageCon, a one-of-a-kind event that helps attendees create the most engaging visual experiences possible.

Read more