Cloudinary Blog

Automatic face-blurring in images made easy

Automatically Blur Faces by Using the Pixelate Effect on Photos
After our recent, somewhat technical posts, we wanted to lighten things up with Cloudinary's latest (cool) semantic image transformation feature. Keeping people privacy in photos by automatically blurring their faces. 
 

Pixelate Effect

We previously detailed in length about Cloudinary's cloud-based API for applying effects on images. We now want to introduce Cloudinary’s latest effect - pixelization.
 
 
Use it by simply setting the 'effect' parameter (or 'e' for URLs) to 'pixelate'.
 
The example below generated a 150x200 thumbnail of a Facebook profile picture and applied the pixelization effect on it.
 
.../image/facebook/w_150,h_200,c_fill,e_pixelate/zuck.jpg
 
 
 
Isn't that great? With zero effort, you've converted an image to a pixelated one before embedding it in your site.
 
page load speed
 
As you can see, the pixelate effect in the example above is quite intense. You can assume greater control on the effect’s intensity by specifying the size of the pixelization squares (numeric value, in pixels). In the following example, we applied the pixelate effect using six pixel blocks on the same Facebook profile picture that was automatically retrieved from Facebook by Cloudinary. As always, the resulting image is cached and delivered through a fast CDN.
 
.../image/facebook/w_150,h_200,c_fill,e_pixelate:6/zuck.jpg
 
 
 
Same example in Ruby on Rails, Django, Node.js and PHP:
 
Copy to clipboard
<%= facebook_profile_image_tag("zuck.jpg", :effect => "pixelate:6", 
                               :width => 150, :height => 200, :crop => :fill) %gt;
Copy to clipboard
{% cloudinary "zuck.jpg" type="facebook" effect="pixelate:6" 
              width=150 height=200 crop="fill"  %}
Copy to clipboard
cloudinary.image("zuck.jpg", { type: "facebook",  effect: "pixelate:6", 
                 width: 150, height: 200, crop: "fill"})
Copy to clipboard
<?php echo facebook_profile_image_tag("zuck.jpg", array("effect" => "pixelate:6", 
                             "width" => 150, "height" => 200, "crop" => "fill")) ?>

 

Automatic Face Blurring

In the examples above we've shown how to easily pixelate a whole picture. But if we are talking about privacy, showing the original image as is and just hiding the faces is probably more useful.
 
For example, let's take the following photo, depicting a nice couple:
 
 
 
 
We can now apply the new 'pixelate_faces' effect to hide the faces of the couple in the original image. The following URL generates a 200x200 rounded cornered thumbnail that was smartly cropped based of face detection, while blurring the faces in the process.
 
 
 
 
As you can see, all parts of the images are still clear while the faces in the picture were automatically detected and pixelated by Cloudinary.
 
Same example in Ruby on Rails, Django, Node.js and PHP:
 
Copy to clipboard
<%= cl_image_tag("couple.jpg", :effect => "pixelate_faces", :width => 200, 
                 :height => 200, :crop => :thumb, :gravity => :faces, :radius => 20) %>
Copy to clipboard
{% cloudinary "couple.jpg" effect="pixelate_faces" width=200 height=200 
              crop="thumb" gravity="faces" radius=20  %}
Copy to clipboard
cloudinary.image("couple.jpg", { effect: "pixelate_faces", width: 200, 
                 height: 200, crop: "thumb", gravity: "faces", radius: 20})
Copy to clipboard
<?php echo cl_image_tag("couple.jpg", array("effect" => "pixelate_faces", 
                        "width" => 200, "height" => 200, "crop" => "thumb", 
                        "gravity" => "faces", "radius" => 20)) ?>
 
With the pixelate faces effect, you can pixelate one or more faces automatically. You can even pixelate the faces of a whole soccer team as seen in the example below. Here, Cloudinary automatically fetches the remote image from Wikimedia Commons and applies the pixelate faces effect before delivery through a CDN:
 
 
 
If you are a Spanish or a European football fan, you probably recognized all players in the picture despite the heavy pixelization :) 
 
As with the pixelate effect, the pixelate_faces effect also supports specifying the number of pixels to use for each pixelization block. The following example applies a 4-pixels effect on the same remote image for making it easier for you to recognize the players...
 
 
  

Face Blurring as Incoming Transformation 

For simplicity, all the examples given above were applied on the images on-demand. A user, looking at the image source, may craft a URL that does not include the blur. 
 
To prevent access to the original image, you should apply the pixelate effect as part of an incoming transforming while uploading the image to Cloudinary and before it is stored in the cloud for delivery. Alternatively, you can also upload images as private images as we described in a previous blog post

Summary 

We've had great fun introducing this feature, and personally think it's quite cool :)
 
Sites with user generated content, news sites and dating sites might find this feature very useful. Note however that automatic face detection is not perfect, and faces might not be detected and pixelated if the face in the picture is not clear enough. If you are going to incorporate face blurring in your system, you might want to introduce it as a part of a semi-automatic moderation system. By suggesting the automatically censored photo to a human moderator, you will save lengthy manual image processing time, while allowing the moderator to override incorrectly censored photos.
 
This feature was actually not in our original plans or to-do list. It was requested by one of our clients. Thankfully, the Cloudinary system was built with enough flexibility to introduce this new feature in no time. We were especially lucky to be able to reuse many existing building blocks - face detection, image effects support, best of breed image transformation software and more.
 
If you need a yet unsupported cloud-based image transformation for your own web application, why don't you go ahead and challenge us?

Recent Blog Posts

Get Your Media Moving Faster with Cloudinary’s Media Optimizer

So, your boss comes to you in a panic: he's just heard about Google's Core Web Vitals initiative and needs you to optimize the company website right now! "No problem," you say, hiding your fear that it's not something that can be done overnight. Just taking the first metric, Largest Contentful Paint (LCP), how can you possibly identify all the large elements - most likely images or video posters - of the many hundreds of pages that make up your site? There are already thousands of high-resolution (read massive) media files stored away, which marketing could use any time. How are you going to make sure they're all compressed to a size small enough to be delivered within the threshold? Not to mention all the new images and videos that will be created over time...

Read more
How to Tap Into the Value of User-Generated Content (UGC)

User-generated content (UGC) took off with, first of all, the advent of the internet and, subsequently, social networks. Everyday consumers were given keys to the kingdom, so to speak, so that they, too, could compose and post content, simultaneously engaging with others online. Twitter, Facebook, Instagram, Snapchat, TikTok—the networks through which we can create and publish content have grown exponentially, and brands are becoming aware of the benefits of tapping into the gold mines offered by those networks.

Read more
Identifying Countries by IP Address in Columnar Databases Through SQL

Cloudinary reaps a myriad of open web traffic, from ad networks to e-commerce sites. Our Data Science team is dedicated to analyzing the data for use internally and externally.

A glance at any General Data Protection Regulation (GDPR) article would reveal that—unlike Android device IDs (AID), through which users can reset their web address—keeping user identifiers, such as Internal Protocol (IP) and Media Access Control (MAC) addresses, as well as International Mobile Equipment Identity (IMEI), violates privacy. As a solution, you can discard all privacy identifications or make them visible to users for reset.

Read more
Digital-First Asset Management Explained

As the world changes, so does technology. I don’t need to name more than a handful of antiquated technologies before you nod in agreement: floppy disks, Walkmans, phone booths, VHS tapes, each of which have been phased out or rendered useless by new solutions that meet the same need but much more effectively.

Read more
How to Build Workflows With Cloudinary’s MediaFlows

Many of you who work with the Cloudinary platform have a media-associated workflow for moderation of images, dispatch of notifications with certain data or headers, implementation of activities through add-ons, etc. For most of those cases, Cloudinary would suggest that you take advantage of our webhook notifications and build the workflow with an infrastructure like AWS Lambda. This post describes how to do that with Cloudinary’s MediaFlows a beta product that helps tackle management and operational tasks related to visual media.

Read more