Cloudinary Blog

Adding borders to images

Graphic designers often contemplate whether to add borders to their website elements. The decision of whether to add borders around frames, buttons and text elements really depends on the feeling the designer is trying to convey through the design. 
 
In this blog post we wanted to tell you about a new cloud-based transformation available through Cloudinary - adding borders to images. Yes, you can use CSS3 or image masks to simulate borders around images, but the first is supported only on modern browsers and the latter clutters the HTML. In addition, if you plan on embedding images in emails or documents you can pretty much say goodbye to borders (certainly for images with rounded corners). For such cases, you can use Cloudinary's extremely simple image transformation API to add borders directly to the original image.
 
Consider the following photo. It was uploaded to Cloudinary using 'autumn_leaves' as its public ID:
 
 
Adding a border around the image is straightforward. Simply specify the 'border' parameter ('bo' for URLs) using a CSS-like format. In the following example '4px_solid_black' means a 4 pixels wide black border.
 
 
 
 
Same example in Ruby on Rails:
Copy to clipboard
<% cl_image_tag("autumn_leaves.jpg", :width => 0.15, :crop => :scale, 
                :border => { :width => 4, :color => 'black' }) %>
 
The border's color component also accepts RGB format. The following example rounds the corners of the image using the 'radius' parameter ('r' for URLs) and adds a 6 pixels solid green border ('#00390b').
 
 
 
Same example in PHP:
Copy to clipboard
<?php echo cl_image_tag("autumn_leaves.jpg", array("width" => 0.15, "crop" => "scale", 
       "radius" => 20, "border" => array("width" => 6, "color" => "#00390b"))) ?>
 
Cloudinary also supports adding semi-transparent borders. This is accomplished using the RGBA color format. The Alpha hex value ranges between 00 (fully transparent), to FF (opaque). The following example generates a semi transparent 10 pixels wide green border. We also use Cloudinary's chained transformations to make the image elliptic ('max' radius), rotate the image by 5 degrees and add an underlay blue background image (while resizing it and increasing its brightness).
 
 
 
Same example in Django:
Copy to clipboard
import cloudinary
img = cloudinary.CloudinaryImage("autumn_leaves.jpg")
img.image(transformation=[
          dict(width=0.15, crop='scale', radius='max', 
               border=dict(width=10, color='#00390b60')), 
          dict(angle=5), 
          dict(underlay='site_bg', width=250, height=200, effects='brightness:50')])
And one last example - the following URL generates an image based on a Facebook profile picture that was automatically fetched by Cloudinary. The image is resized and rounded, and a black border is added. We then use an overlay to add Cloudinary's logo with a semi-transparent wide border. As with all of the Cloudinary managed images, the resulting image is persistently stored in the Cloud and then delivered and cached through a fast CDN.
 
 
 
By the way, you can also add the border as an incoming transformation so the original image is stored in the cloud already with the border. Here's such an incoming transformation, this time in Node.js:
Copy to clipboard
cloudinary.image("itail.jpg", { type: 'facebook', transformation: [
                 { crop: 'fill', width: 150, height: 180, radius: 10, 
                   border: { width: 2, color: 'black'}},
                 { overlay: 'cloudinary_logo_white', width: 90, 
                   gravity: 'south_east', radius: 5, y: 7, x: 7, 
                   border: { width: 6, color: '#afcee990'}}]})

Summary

If you are a regular reader of our blog, you know that Cloudinary keeps enhancing on various fronts. One of these fronts is our ever increasing set of image manipulation capabilities. In this blog we introduced a cool new enhancement that you might find useful. We have more in our pipeline. If you want to see a new image manipulation capability added to Cloudinary, just drop us a line.

Recent Blog Posts

Generate Waveform Images from Audio with Cloudinary

This is a reposting of an article written by David Walsh. Check out his blog HERE!
I've been working a lot with visualizations lately, which is a far cry from your normal webpage element interaction coding; you need advanced geometry knowledge, render and performance knowledge, and much more. It's been a great learning experience but it can be challenging and isn't always an interest of all web developers. That's why we use apps and services specializing in complex tasks like Cloudinary: we need it done quickly and by a tool written by an expert.

Read more
Make All Images on Your Website Responsive in 3 Easy Steps

Images are crucial to website performance, but most still don't implement responsive images. It’s not just about fitting an image on the screen, but also making the the image size relatively rational to the device. The srcset and sizes options, which are your best hit are hard to implement. Cloudinary provides an easier way, which we will discuss in this article.

Read more

The Future of Audio and Video on the Web

By Prosper Otemuyiwa
The Future of Audio and Video on the Web

Web sites and platforms are becoming increasingly media-rich. Today, approximately 62 percent of internet traffic is made up of images, with audio and video constituting a growing percentage of the bytes.

Read more

Embed Images in Email Campaigns at Scale

By Sourav Kundu
Embed Images in Email Campaigns at Scale

tl;dr

Cloudinary is a powerful image hosting solution for email marketing campaigns of any size. With features such as advanced image optimization and on-the-fly image transformation, backed by a global CDN, Cloudinary provides the base for a seamless user experience in your email campaigns leading to increased conversion and performance.

Read more
Build the Back-End For Your Own Instagram-style App with Cloudinary

Github Repo

Managing media files (processing, storage and manipulation) is one of the biggest challenges we encounter as practical developers. These challenges include:

A great service called Cloudinary can help us overcome many of these challenges. Together with Cloudinary, let's work on solutions to these challenges and hopefully have a simpler mental model towards media management.

Read more

Build A Miniflix in 10 Minutes

By Prosper Otemuyiwa
Build A Miniflix in 10 Minutes

Developers are constantly faced with challenges of building complex products every single day. And there are constraints on the time needed to build out the features of these products.

Engineering and Product managers want to beat deadlines for projects daily. CEOs want to roll out new products as fast as possible. Entrepreneurs need their MVPs like yesterday. With this in mind, what should developers do?

Read more