Documentation Index

Fetch the complete documentation index at: https://cloudinary.com/documentation/llms.txt

Use this file to discover all available pages before exploring further.

Image & Video APIs

How do I add a solid color shape over part of an image?

Last updated: Nov-09-2026

Quick answer
To place a solid color shape over part of an image, overlay a 1x1 pixel image, stretch it to the size you want, color it, and position it. This example puts a semi-transparent red square over the detected face:

l_docs:one_black_pixel/h_130,w_130/co_red,e_colorize/o_50/fl_layer_apply,g_face

Replace docs:one_black_pixel with the public ID of a 1x1 pixel image in your own product environment, with colons in place of any slashes. You can download the 1x1 pixel image and upload it to your product environment.

The question

"How do I add a solid color box over part of an image, such as over someone's face?"

Cloudinary has no dedicated "draw a shape" transformation. Instead, you overlay a tiny solid-color image and stretch it into the shape you need. People use this to:

  • Highlight an area: drawing attention to part of an image with a colored marker.
  • Mask content: covering part of an image, such as a name or a face.
  • Add design elements: adding color blocks behind or beside other layers.

The original asset

The examples start with this photo of a person:

Original photo of a woman in a gray sweater

The solution

  1. Upload a 1x1 pixel image to your product environment. You can download the one used in these examples, which has the public ID docs/one_black_pixel in the demo product environment. In an overlay (l_), replace each slash in the public ID with a colon, as in l_docs:one_black_pixel.
  2. Add it as an overlay (l_) and set its width (w_) and height (h_) in pixels. Equal values make a square.
  3. Apply the layer with fl_layer_apply.

This example stretches the pixel to 130x130 pixels. With no gravity, the layer sits in the center of the image:

Photo with a black square in the center


Change the color of the shape

To change the color, add e_colorize and co_<color> to the layer, before fl_layer_apply:

Photo with a red square in the center


Position the shape on a detected face

To center the shape on the face in the image, add g_face to the fl_layer_apply component:

Photo with a red square over the detected face


To place the shape anywhere else, use a gravity (such as g_north_west) with the x_ and y_ offsets, in the same component as fl_layer_apply.

The shape stays the size that you set with h_ and w_, and doesn't resize to fit the face. Check that it covers the face in your images, or size it as a fraction of the image with fl_relative.

Make the shape see-through

To let the image show through the shape, add the opacity parameter (o_) to the layer, before fl_layer_apply. This example uses 50% opacity:

Photo with a semi-transparent red square over the detected face


Note
To hide a face for privacy, use a fully opaque shape, or use the blur or pixelate faces effects instead. A see-through shape doesn't hide the face.

Related topics

✔️ Feedback sent!

Rate this page:

one star two stars three stars four stars five stars