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:
cl_image_tag("front_face.jpg")
PHP:
cl_image_tag("front_face.jpg")
Python:
CloudinaryImage("front_face.jpg").image()
Node.js:
cloudinary.image("front_face.jpg")
Java:
cloudinary.url().imageTag("front_face.jpg")
JS:
cl.imageTag('front_face.jpg').toHtml();
jQuery:
$.cloudinary.image("front_face.jpg")
React:
<Image publicId="front_face.jpg" >

</Image>
Angular:
<cl-image public-id="front_face.jpg" >

</cl-image>
.Net:
cloudinary.Api.UrlImgUp.BuildImageTag("front_face.jpg")
Original

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

Ruby:
cl_image_tag("front_face.jpg", :radius=>50)
PHP:
cl_image_tag("front_face.jpg", array("radius"=>50))
Python:
CloudinaryImage("front_face.jpg").image(radius=50)
Node.js:
cloudinary.image("front_face.jpg", {radius: 50})
Java:
cloudinary.url().transformation(new Transformation().radius(50)).imageTag("front_face.jpg")
JS:
cl.imageTag('front_face.jpg', {radius: 50}).toHtml();
jQuery:
$.cloudinary.image("front_face.jpg", {radius: 50})
React:
<Image publicId="front_face.jpg" >
  <Transformation radius="50" />
</Image>
Angular:
<cl-image public-id="front_face.jpg" >
  <cl-transformation radius="50">
  </cl-transformation>
</cl-image>
.Net:
cloudinary.Api.UrlImgUp.Transform(new Transformation().Radius(50)).BuildImageTag("front_face.jpg")
Rounded corners

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

Ruby:
cl_image_tag("front_face.png", :radius=>50)
PHP:
cl_image_tag("front_face.png", array("radius"=>50))
Python:
CloudinaryImage("front_face.png").image(radius=50)
Node.js:
cloudinary.image("front_face.png", {radius: 50})
Java:
cloudinary.url().transformation(new Transformation().radius(50)).imageTag("front_face.png")
JS:
cl.imageTag('front_face.png', {radius: 50}).toHtml();
jQuery:
$.cloudinary.image("front_face.png", {radius: 50})
React:
<Image publicId="front_face.png" >
  <Transformation radius="50" />
</Image>
Angular:
<cl-image public-id="front_face.png" >
  <cl-transformation radius="50">
  </cl-transformation>
</cl-image>
.Net:
cloudinary.Api.UrlImgUp.Transform(new Transformation().Radius(50)).BuildImageTag("front_face.png")
Rounded corners

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

Ruby:
cl_image_tag("front_face.png", :radius=>20)
PHP:
cl_image_tag("front_face.png", array("radius"=>20))
Python:
CloudinaryImage("front_face.png").image(radius=20)
Node.js:
cloudinary.image("front_face.png", {radius: 20})
Java:
cloudinary.url().transformation(new Transformation().radius(20)).imageTag("front_face.png")
JS:
cl.imageTag('front_face.png', {radius: 20}).toHtml();
jQuery:
$.cloudinary.image("front_face.png", {radius: 20})
React:
<Image publicId="front_face.png" >
  <Transformation radius="20" />
</Image>
Angular:
<cl-image public-id="front_face.png" >
  <cl-transformation radius="20">
  </cl-transformation>
</cl-image>
.Net:
cloudinary.Api.UrlImgUp.Transform(new Transformation().Radius(20)).BuildImageTag("front_face.png")
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:
cl_image_tag("front_face.png", :width=>100, :height=>150, :gravity=>"face", :radius=>"max", :crop=>"fill")
PHP:
cl_image_tag("front_face.png", array("width"=>100, "height"=>150, "gravity"=>"face", "radius"=>"max", "crop"=>"fill"))
Python:
CloudinaryImage("front_face.png").image(width=100, height=150, gravity="face", radius="max", crop="fill")
Node.js:
cloudinary.image("front_face.png", {width: 100, height: 150, gravity: "face", radius: "max", crop: "fill"})
Java:
cloudinary.url().transformation(new Transformation().width(100).height(150).gravity("face").radius("max").crop("fill")).imageTag("front_face.png")
JS:
cl.imageTag('front_face.png', {width: 100, height: 150, gravity: "face", radius: "max", crop: "fill"}).toHtml();
jQuery:
$.cloudinary.image("front_face.png", {width: 100, height: 150, gravity: "face", radius: "max", crop: "fill"})
React:
<Image publicId="front_face.png" >
  <Transformation width="100" height="150" gravity="face" radius="max" crop="fill" />
</Image>
Angular:
<cl-image public-id="front_face.png" >
  <cl-transformation width="100" height="150" gravity="face" radius="max" crop="fill">
  </cl-transformation>
</cl-image>
.Net:
cloudinary.Api.UrlImgUp.Transform(new Transformation().Width(100).Height(150).Gravity("face").Radius("max").Crop("fill")).BuildImageTag("front_face.png")
Elipse

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

Ruby:
cl_image_tag("front_face.png", :width=>150, :height=>150, :gravity=>"face", :radius=>"max", :crop=>"fill")
PHP:
cl_image_tag("front_face.png", array("width"=>150, "height"=>150, "gravity"=>"face", "radius"=>"max", "crop"=>"fill"))
Python:
CloudinaryImage("front_face.png").image(width=150, height=150, gravity="face", radius="max", crop="fill")
Node.js:
cloudinary.image("front_face.png", {width: 150, height: 150, gravity: "face", radius: "max", crop: "fill"})
Java:
cloudinary.url().transformation(new Transformation().width(150).height(150).gravity("face").radius("max").crop("fill")).imageTag("front_face.png")
JS:
cl.imageTag('front_face.png', {width: 150, height: 150, gravity: "face", radius: "max", crop: "fill"}).toHtml();
jQuery:
$.cloudinary.image("front_face.png", {width: 150, height: 150, gravity: "face", radius: "max", crop: "fill"})
React:
<Image publicId="front_face.png" >
  <Transformation width="150" height="150" gravity="face" radius="max" crop="fill" />
</Image>
Angular:
<cl-image public-id="front_face.png" >
  <cl-transformation width="150" height="150" gravity="face" radius="max" crop="fill">
  </cl-transformation>
</cl-image>
.Net:
cloudinary.Api.UrlImgUp.Transform(new Transformation().Width(150).Height(150).Gravity("face").Radius("max").Crop("fill")).BuildImageTag("front_face.png")
Circle

Any further image transformations can be also applied.

by Itay Taragano
Tags: