Cloudinary Blog

Image opacity manipulation and dynamic watermark generation

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 manipulation 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, manipulating 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 manipulate 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
<%= cl_image_tag("mountain.jpg", :opacity => 20) %>
<?php echo cl_image_tag("mountain.jpg", array("opacity" => 20)) ?>
import cloudinary
img = cloudinary.CloudinaryImage("mountain.jpg")
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 manipulation transformation, you can upload your non-transparent watermark image and manipulate 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:
<%= cl_image_tag("mountain.jpg", :opacity => 30, :effect => "brightness:20", 
                  :width => 200, :overlay => "cloudinary_icon") %>
<?php echo cl_image_tag("mountain.jpg", array("opacity" => 30, 
  "effect" => "brightness:20", "width" => 200, "overlay" => "cloudinary_icon")) ?>
import cloudinary
img = cloudinary.CloudinaryImage("mountain.jpg")
img.image(opacity=30, effect="brightness:20", width=200, overlay="cloudinary_icon")
  { opacity: 30, effect: "brightness:20", width: 200, overlay: "cloudinary_icon" });


Dynamic opacity manipulation and watermark generation are some of the newest Cloudinary capabilities in your image manipulation 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

Build a WhatsApp Clone with Automatic Image Optimization

In the previous post, we showed how to upload images to a Cloudinary server. In this part, we will play with some of the features we see on the WhatsApp technology. After you or your users have uploaded image assets to Cloudinary, you can deliver them via dynamic URLs. You can include instructions in your dynamic URLs that tell Cloudinary to manipulate your assets using a set of transformation parameters. All image manipulations and image optimizations are performed automatically in the cloud and your transformed assets are automatically optimized before they are routed through a fast CDN to the end user for an optimal user experience. For example, you can resize and crop, add overlays, blur or pixelate faces, apply a variety of special effects and filters, and apply settings to optimize your images and to deliver them responsively.

Read more
With automatic video subtitles, silence speaks volumes

The last time you scrolled through the feed on your favorite social site, chances are that some videos caught your attention, and chances are, they were playing silently.

On the other hand, what was your reaction the last time you opened a web page and a video unexpectedly began playing with sound? If you are anything like me, the first thing you did was to quickly hunt for the fastest way to pause the video, mute the sound, or close the page entirely, especially if you were in a public place at the time.

Read more
Impressed by WhatsApp Tech? Build WhatsApp Clone with Media Upload

With more than one billion people using WhatsApp, the platform is becoming a go-to for reliable and secure instant messaging. Having so many users means that data transfer processes must be optimized and scalable across all platforms. WhatsApp is touted for its ability to achieve significant media quality preservation when traversing the network from sender to receiver, and this is no easy feat to achieve.

Read more
New Google-powered add-on for auto video categories and tags

Due to significant growth of the web and improvements in network bandwidth, video is now a major source of information and entertainment shared over the internet. As a developer or asset manager, making corporate videos available for viewing, not to mention user-uploaded videos, means you also need a way to categorize them according to their content and make your video library searchable. Most systems end up organizing their video by metadata like the filename, or with user-generated tags (e.g., youtube). This sort of indexing method is subjective, inconsistent, time-consuming, incomplete and superficial.

Read more

iOS Developer Camp: The Dog House

By Shantini Vyas
iOS Developer Camp: The Dog House

Confession: I’m kind of addicted to hackathons. Ever since graduating from Coding Dojo earlier this year, I’ve been on the hunt for new places to expand my skills and meet new people in the tech space. iOS Developer Camp’s 10th Anniversary event bowled me over. Initially, because of its length. 48 hours? Yeesh. I had no idea that those 48 hours would change my life. But let’s first get a little backstory on my favorite topic: dogs.

Read more