Applying rounded corners to an image

Transforming an image to a rounded version is simply done by using the radius parameter (r in URLs). It accepts the number of pixels of the radius of all four corners.

Many website designs call for images with rounded corners, while some websites require images with a complete circular or oval (ellipse) crop. Twitter, for example, uses rounded corners for its users' profile pictures. Having images with rounded corners is great if you want to simplify your CSS and markup or when you need to support older browsers. With Cloudinary, rounding the corners of the image can be easily done on-the-fly in the cloud.

Here's an original sample image:

Ruby:
Copy to clipboard
cl_image_tag("front_face.jpg")
PHP:
Copy to clipboard
cl_image_tag("front_face.jpg")
Python:
Copy to clipboard
CloudinaryImage("front_face.jpg").image()
Node.js:
Copy to clipboard
cloudinary.image("front_face.jpg")
Java:
Copy to clipboard
cloudinary.url().imageTag("front_face.jpg");
JS:
Copy to clipboard
cloudinary.imageTag('front_face.jpg').toHtml();
jQuery:
Copy to clipboard
$.cloudinary.image("front_face.jpg")
React:
Copy to clipboard
<Image publicId="front_face.jpg" >

</Image>
Vue.js:
Copy to clipboard
<cld-image publicId="front_face.jpg" >

</cld-image>
Angular:
Copy to clipboard
<cl-image public-id="front_face.jpg" >

</cl-image>
.Net:
Copy to clipboard
cloudinary.Api.UrlImgUp.BuildImageTag("front_face.jpg")
Android:
Copy to clipboard
MediaManager.get().url().generate("front_face.jpg");
iOS:
Copy to clipboard
imageView.cldSetImage(cloudinary.createUrl().generate("front_face.jpg")!, cloudinary: cloudinary)
Original

Here's the same image with rounded corners of 30 pixels.

Ruby:
Copy to clipboard
cl_image_tag("front_face.jpg", :radius=>50)
PHP:
Copy to clipboard
cl_image_tag("front_face.jpg", array("radius"=>50))
Python:
Copy to clipboard
CloudinaryImage("front_face.jpg").image(radius=50)
Node.js:
Copy to clipboard
cloudinary.image("front_face.jpg", {radius: 50})
Java:
Copy to clipboard
cloudinary.url().transformation(new Transformation().radius(50)).imageTag("front_face.jpg");
JS:
Copy to clipboard
cloudinary.imageTag('front_face.jpg', {radius: 50}).toHtml();
jQuery:
Copy to clipboard
$.cloudinary.image("front_face.jpg", {radius: 50})
React:
Copy to clipboard
<Image publicId="front_face.jpg" >
  <Transformation radius="50" />
</Image>
Vue.js:
Copy to clipboard
<cld-image publicId="front_face.jpg" >
  <cld-transformation radius="50" />
</cld-image>
Angular:
Copy to clipboard
<cl-image public-id="front_face.jpg" >
  <cl-transformation radius="50">
  </cl-transformation>
</cl-image>
.Net:
Copy to clipboard
cloudinary.Api.UrlImgUp.Transform(new Transformation().Radius(50)).BuildImageTag("front_face.jpg")
Android:
Copy to clipboard
MediaManager.get().url().transformation(new Transformation().radius(50)).generate("front_face.jpg");
iOS:
Copy to clipboard
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setRadius(50)).generate("front_face.jpg")!, cloudinary: cloudinary)
Rounded corners

Note that the conversion to PNG is needed for supporting a transparent background:

Ruby:
Copy to clipboard
cl_image_tag("front_face.png", :radius=>50)
PHP:
Copy to clipboard
cl_image_tag("front_face.png", array("radius"=>50))
Python:
Copy to clipboard
CloudinaryImage("front_face.png").image(radius=50)
Node.js:
Copy to clipboard
cloudinary.image("front_face.png", {radius: 50})
Java:
Copy to clipboard
cloudinary.url().transformation(new Transformation().radius(50)).imageTag("front_face.png");
JS:
Copy to clipboard
cloudinary.imageTag('front_face.png', {radius: 50}).toHtml();
jQuery:
Copy to clipboard
$.cloudinary.image("front_face.png", {radius: 50})
React:
Copy to clipboard
<Image publicId="front_face.png" >
  <Transformation radius="50" />
</Image>
Vue.js:
Copy to clipboard
<cld-image publicId="front_face.png" >
  <cld-transformation radius="50" />
</cld-image>
Angular:
Copy to clipboard
<cl-image public-id="front_face.png" >
  <cl-transformation radius="50">
  </cl-transformation>
</cl-image>
.Net:
Copy to clipboard
cloudinary.Api.UrlImgUp.Transform(new Transformation().Radius(50)).BuildImageTag("front_face.png")
Android:
Copy to clipboard
MediaManager.get().url().transformation(new Transformation().radius(50)).generate("front_face.png");
iOS:
Copy to clipboard
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setRadius(50)).generate("front_face.png")!, cloudinary: cloudinary)
Rounded corners

Any other radius value is accepted of course, for example - '20':

Ruby:
Copy to clipboard
cl_image_tag("front_face.png", :radius=>20)
PHP:
Copy to clipboard
cl_image_tag("front_face.png", array("radius"=>20))
Python:
Copy to clipboard
CloudinaryImage("front_face.png").image(radius=20)
Node.js:
Copy to clipboard
cloudinary.image("front_face.png", {radius: 20})
Java:
Copy to clipboard
cloudinary.url().transformation(new Transformation().radius(20)).imageTag("front_face.png");
JS:
Copy to clipboard
cloudinary.imageTag('front_face.png', {radius: 20}).toHtml();
jQuery:
Copy to clipboard
$.cloudinary.image("front_face.png", {radius: 20})
React:
Copy to clipboard
<Image publicId="front_face.png" >
  <Transformation radius="20" />
</Image>
Vue.js:
Copy to clipboard
<cld-image publicId="front_face.png" >
  <cld-transformation radius="20" />
</cld-image>
Angular:
Copy to clipboard
<cl-image public-id="front_face.png" >
  <cl-transformation radius="20">
  </cl-transformation>
</cl-image>
.Net:
Copy to clipboard
cloudinary.Api.UrlImgUp.Transform(new Transformation().Radius(20)).BuildImageTag("front_face.png")
Android:
Copy to clipboard
MediaManager.get().url().transformation(new Transformation().radius(20)).generate("front_face.png");
iOS:
Copy to clipboard
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setRadius(20)).generate("front_face.png")!, cloudinary: cloudinary)
Rounded corners

You can apply rounded corners on any image, for example, here's how to round the corners of a Facebook Profile pictures fetched in real-time:

Facebook picture

Cloudinary supports cropping images to a shape of an ellipse or a circle by passing max as the value of the radius parameter (r_max in URLs). The following example transforms an uploaded JPG to a 100x150 PNG with max radius cropping, which generates the ellipse shape based on the detected face, with a transparent background:

Ruby:
Copy to clipboard
cl_image_tag("front_face.png", :width=>100, :height=>150, :gravity=>"face", :radius=>"max", :crop=>"fill")
PHP:
Copy to clipboard
cl_image_tag("front_face.png", array("width"=>100, "height"=>150, "gravity"=>"face", "radius"=>"max", "crop"=>"fill"))
Python:
Copy to clipboard
CloudinaryImage("front_face.png").image(width=100, height=150, gravity="face", radius="max", crop="fill")
Node.js:
Copy to clipboard
cloudinary.image("front_face.png", {width: 100, height: 150, gravity: "face", radius: "max", crop: "fill"})
Java:
Copy to clipboard
cloudinary.url().transformation(new Transformation().width(100).height(150).gravity("face").radius("max").crop("fill")).imageTag("front_face.png");
JS:
Copy to clipboard
cloudinary.imageTag('front_face.png', {width: 100, height: 150, gravity: "face", radius: "max", crop: "fill"}).toHtml();
jQuery:
Copy to clipboard
$.cloudinary.image("front_face.png", {width: 100, height: 150, gravity: "face", radius: "max", crop: "fill"})
React:
Copy to clipboard
<Image publicId="front_face.png" >
  <Transformation width="100" height="150" gravity="face" radius="max" crop="fill" />
</Image>
Vue.js:
Copy to clipboard
<cld-image publicId="front_face.png" >
  <cld-transformation width="100" height="150" gravity="face" radius="max" crop="fill" />
</cld-image>
Angular:
Copy to clipboard
<cl-image public-id="front_face.png" >
  <cl-transformation width="100" height="150" gravity="face" radius="max" crop="fill">
  </cl-transformation>
</cl-image>
.Net:
Copy to clipboard
cloudinary.Api.UrlImgUp.Transform(new Transformation().Width(100).Height(150).Gravity("face").Radius("max").Crop("fill")).BuildImageTag("front_face.png")
Android:
Copy to clipboard
MediaManager.get().url().transformation(new Transformation().width(100).height(150).gravity("face").radius("max").crop("fill")).generate("front_face.png");
iOS:
Copy to clipboard
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setWidth(100).setHeight(150).setGravity("face").setRadius("max").setCrop("fill")).generate("front_face.png")!, cloudinary: cloudinary)
Elipse

Setting the width and height to the same value will generate a circle:

Ruby:
Copy to clipboard
cl_image_tag("front_face.png", :width=>150, :height=>150, :gravity=>"face", :radius=>"max", :crop=>"fill")
PHP:
Copy to clipboard
cl_image_tag("front_face.png", array("width"=>150, "height"=>150, "gravity"=>"face", "radius"=>"max", "crop"=>"fill"))
Python:
Copy to clipboard
CloudinaryImage("front_face.png").image(width=150, height=150, gravity="face", radius="max", crop="fill")
Node.js:
Copy to clipboard
cloudinary.image("front_face.png", {width: 150, height: 150, gravity: "face", radius: "max", crop: "fill"})
Java:
Copy to clipboard
cloudinary.url().transformation(new Transformation().width(150).height(150).gravity("face").radius("max").crop("fill")).imageTag("front_face.png");
JS:
Copy to clipboard
cloudinary.imageTag('front_face.png', {width: 150, height: 150, gravity: "face", radius: "max", crop: "fill"}).toHtml();
jQuery:
Copy to clipboard
$.cloudinary.image("front_face.png", {width: 150, height: 150, gravity: "face", radius: "max", crop: "fill"})
React:
Copy to clipboard
<Image publicId="front_face.png" >
  <Transformation width="150" height="150" gravity="face" radius="max" crop="fill" />
</Image>
Vue.js:
Copy to clipboard
<cld-image publicId="front_face.png" >
  <cld-transformation width="150" height="150" gravity="face" radius="max" crop="fill" />
</cld-image>
Angular:
Copy to clipboard
<cl-image public-id="front_face.png" >
  <cl-transformation width="150" height="150" gravity="face" radius="max" crop="fill">
  </cl-transformation>
</cl-image>
.Net:
Copy to clipboard
cloudinary.Api.UrlImgUp.Transform(new Transformation().Width(150).Height(150).Gravity("face").Radius("max").Crop("fill")).BuildImageTag("front_face.png")
Android:
Copy to clipboard
MediaManager.get().url().transformation(new Transformation().width(150).height(150).gravity("face").radius("max").crop("fill")).generate("front_face.png");
iOS:
Copy to clipboard
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setWidth(150).setHeight(150).setGravity("face").setRadius("max").setCrop("fill")).generate("front_face.png")!, cloudinary: cloudinary)
Circle

Any further image transformations can be also applied.

by Itay Taragano
Tags: