ImageKit enables you to creatively enhance your images by adding overlays such as images, text, or solid color blocks using layers. This guide provides quick links to examples demonstrating these features.
For further details and in-depth examples, refer to the corresponding sections within this guide. Ensure to review the limits on resource-intensive transformations before deploying these features in production.
Add images over image
You can add an image over a base image using the following syntax.
Image overlay syntax
URL endpoint Base image Image layer ┌──────────────────────────┐┌────────────┐ ┌──────────────────────┐ https://ik.imagekit.io/demo/base-image.jpg?tr=l-image,i-logo.png,l-end
URL - https://ik.imagekit.io/demo/tr:l-image,i-logo-white_SJwqB4Nfe.png,l-end/medium_cafe_B1iTdD0C.jpg
To overlay images stored within a specific folder of your media library, use the complete image path where slashes (/
) are replaced with @@
.
For example, if the overlay image is at https://ik.imagekit.io/demo/path/to/overlay.png
, then it can be used as an overlay like: https://ik.imagekit.io/demo/base-image.jpg?tr=l-image,i-path@@to@@overlay.png,l-end
Control position of image overlay
You can control image layer position using the lx
and ly
parameters. If the lx
or ly
value exceeds the dimensions of the input image, the values are adjusted to fit within the image. To change the direction, negative values are also supported by prefixing the value with 'N'.
Learn more about positional parameters in layers.
Apply transformation on image overlay
Inside an image layer, you can apply these supported transformations to the image overlay before it is placed on the base image. You can chain the transformations one after the other to achieve the desired outcome.
For example, let's resize the overlay image to 400x400 and add a yellow background to fill the image layer's background.
You can also apply additional transformations, such as e-grayscale
, to modify the overlay image. Here's an example of turning the overlay image into a grayscale version.
List of supported image transformations in image layers
Parameter | Description |
---|---|
w | Width of the overlay image. It can also accept arithmetic expressions such as iw_div_2 , or bw_sub_cw . Learn more about arithmetic expressions here. |
h | Height of the overlay image. It can also accept arithmetic expressions such as ih_div_2 , or bh_mul_0.8 . Learn more about arithmetic expressions here. |
ar | Aspect ratio of the overlay image. It can also accept arithmetic expressions such as iar_div_2 , or bar . Learn more about arithmetic expressions here. |
c | Cropping method. Accepts force , at_max , and at_least . |
cm | Crop mode. Supports extract and pad_resize . |
fo | Relative focus area used during cropping. Accepts face , custom , center , top , left , bottom , right , top_left , top_right , bottom_left , and bottom_right . It also supports object-aware cropping. |
z | It determines how much to zoom in or out of the cropped area. It must be used along with fo-face . A value less than 1.0 zooms out to include more background surrounding the face, whereas a value larger than 1.0 zooms in to exclude more background surrounding the face. Possible values include any number between 0 to 1 for zoom out, and greater than 1 for zoom in. Its default value is 1.0 . |
b | It adds a border to the overlay image. It accepts two parameters - the width of the border and the color of the border in format b-<border-width>-<hex code> . It can also accept arithmetic expressions such as bh_mod_5_red , or bw_mul_0.05_FF00FF . Learn more about arithmetic expressions here. |
o | It is used to specify the opacity level of the output image. It accepts numerical values ranging from 0 to 100, where 0 would produce a completely transparent image, and 100 would have no effect. |
bg | It is used to specify the background color in RGB Hex Code (e.g. FF0000 ), or an RGBA Code (e.g. FFAABB50 ), or a color name (e.g. red ) that must be used for the image. If you specify an 8-character background, the last two characters must be a number between 00 and 99, which is used to indicate the opacity level of the background. 00 represents an opacity level of 0.00 , 01 represents an opacity level of 0.01 , and so on. |
r | It is used to control the radius of the corner. To get a circle or oval shape, set the value to max . |
rt | It is used to specify the degree by which the overlay image must be rotated. |
t | By default, ImageKit.io trims the overlay image before overlaying it on the base image. Trimming removes similar colored pixels from the edges. To prevent the default trimming from happening, use t-false . Possible values include true , false , and integer values between 1 and 99 that specify the threshold level for considering a particular pixel as "background". |
dpr | It is used to specify the device pixel ratio that is used to calculate the dimensions of the overlay image. It can only be used when either the height or width of the desired output image is specified. The possible values are 0.1 to 5 , or auto . |
q | It is used to specify the quality of the output image for lossy formats like JPEG, WebP, and AVIF. A large quality number indicates a larger output image size with high quality. A small quality number indicates a smaller output image size with lower quality. It can be a whole number between 1 and 100 . The default value is 80 . |
bl | It is used to specify the Gaussian blur that must be applied to an image. The value of bl specifies the radius of the Gaussian Blur that is to be applied. The higher the value, the larger the radius of the Gaussian Blur. Accepts integers between 1 and 100 . |
x | It is used along with cm-extract to specify the X coordinate of the top-left point where the extract must begin. Possible values are integers, or an arithmetic expression such as iw_div_2 , or bh_sub_100 . Learn more about arithmetic expressions here. |
y | It is used along with cm-extract to specify the Y coordinate of the top-left point where the extract must begin. Possible values are integers, or an arithmetic expression such as ih_div_2 , or bw_sub_150 . Learn more about arithmetic expressions here. |
xc | It is used along with cm-extract to specify the X coordinate of the center point of the image to be extracted. Possible values are integers, or an arithmetic expression such as iw_div_3 , or ih_div_4 . Learn more about arithmetic expressions here. |
yc | It is used along with cm-extract to specify the Y coordinate of the center point of the image to be extracted. Possible values are integers, or an arithmetic expression such as iw_div_3 , or ih_div_4 . Learn more about arithmetic expressions here. |
e-grayscale | It is used to turn an image to a grayscale version. |
e-contrast | It is used to automatically enhance the contrast of the image by using the full intensity values that a particular image format allows. This means that the lighter sections of an image become even lighter and the darker sections become even brighter, thereby enhancing the contrast. |
e-sharpen | It is used to sharpen the input image, useful when highlighting the edges and finer details within an image. If just the e-sharpen parameter is used, then a default sharpening is performed on the input image. This can be controlled by specifying a number that restricts the extent of sharpening performed, like e-sharpen-<number> . |
e-usm | It is used to apply and control unsharp masks on your images. The amount of sharpening can be varied using 4 parameters - radius , sigma , amount , and threshold . This results in perceptually better images compared to using e-sharpen . Only positive floating points are allowed for these 4 parameters. e.g. e-usm-<radius>-<sigma>-<amount>-<threshold> |
e-shadow | It is used to apply a shadow effect on the input image. The strength, blur, and geometrical positioning of the shadow can be varied using the following parameters - st , bl , x and y . e.g. e-shadow-st-<value>_bl-<value>_x-<value>_y-<value> (or simply e-shadow to let the shadow take on default values). Learn more about the shadow effect and its parameters here. |
e-gradient | It is used to add a linear gradient overlay over an input image. The direction, from color, to color, and the stop point of the gradient can be varied using the following parameters - ld , from , to and sp . e.g. e-gradient-<linear-direction>_<from-color>_<to-color>_<stop-point> (or simply e-gradient to let the gradient take on default values). Learn more about the gradient effect and its parameters here. |
Nesting of image layers
A layer can have nested layers up to 3 levels.
Parent image layer ┌──────────────────────────────────────────────────────────────┐ l-image,i-outer.png,l-image,i-inner.png,lfo-top_left,l-end,l-end └──────────────────┬──────────────────┘ │ Nested image layer
In the following example, we overlay the resized women-dress.jpeg
with a red border on the bottom left corner of the base image and then add the imagekit.io
logo on the top right corner of the women-dress.jpeg
image. lfo
parameter is used to control the position of layer in relative terms.
Add text over image
You can add any text string over a base image using the following syntax.
You can also control the position of the text overlay using these positional parameters.
Specified with the i-
parameter in a text
layer. Supported characters include:
- All alphabets and numbers (including Unicode letters, marks, and numerals in other languages)
- Spaces
- Special characters including _, -, %, !, @, and &
URL endpoint Base image Text layer ┌──────────────────────────┐┌────────────┐ ┌──────────────────┐ https://ik.imagekit.io/demo/base-image.jpg?tr=l-text,i-hello,l-end
Plain text input longer than 2000 characters will be truncated.
Let's overlay a text overlay made easy
on top of medium_cafe_B1iTdD0C.jpg
.
https://ik.imagekit.io/demo/tr:l-text,i-overlay%20made%20easy,fs-45,l-end/medium_cafe_B1iTdD0C.jpg
It is specified with the ie-
parameter in a text
layer. It accepts a base64 string as input, allowing you to overlay special Unicode characters (e.g. ©, ®, ™, etc.) that you cannot otherwise pass in a URL as a plain string.
Notes:
- The base64 string should be made URL-safe to ensure that all padding characters(=) are included correctly. In Javascript, a function like
encodeURIComponent()
can be used for this. - Base64 encoded text input longer than 2500 characters will be truncated.
URL endpoint Base image Text layer ┌──────────────────────────┐┌────────────┐ ┌────────────────────────┐ https://ik.imagekit.io/demo/base-image.jpg?tr=l-text,ie-aGVsbG8%3D,l-end
Here aGVsbG8%3D
is the base64 string for "hello".
Text layer dimension limit
If the text layer takes up more than 16,383 pixels horizontally or vertically, then the request will error out.
Let's overlay the text Let's use ©, ®, ™, etc
on top of medium_cafe_B1iTdD0C.jpg
.
Control position of text overlay
You can control text layer position using the lx
and ly
parameters. To change the direction, negative values are also supported by prefixing the value with 'N'.
Learn more about positional parameters in layers.
Apply transformation on text overlay
You can control the width, font size, font family, color, inner alignment, padding, transparency level, typography, background color, corner radius, and line height of the text overlay using these supported transformations parameters.
For example, let's add a white background with padding and a bigger font size.
You can add padding to the text overlay using the pa
parameter. The padding can be controlled individually for each side using the CSS shorthand notation.
- Top padding is 25
- Right padding is 50
- Bottom padding is 75
- Left padding is 100
- Top padding is 25
- Right and left paddings are 75
- Bottom padding is 60
- Top and bottom paddings are 25
- Right and left paddings are 75
Change font family in text overlay
You can change the font family in the text overlay using the ff
parameter. You can use the standard fonts available in ImageKit or upload your custom font file to use it in text overlays.
To use a custom font in text overlays, upload the font file in your media library and pass its path in the ff
parameter in a text layer.
For example, Lacquer-Regular_nGqtVsBJT.ttf
is a custom font file uploaded to the root of the media library and accessible at the URL https://ik.imagekit.io/demo/Lacquer-Regular_nGqtVsBJT.ttf
.
If your custom font file is in a nested folder, then replace the slashes /
in the path with @@
. For example, a font file available at path /font-folder/font-subfolder/my-custom-font.ttf
will be used as follows:
https://ik.imagekit.io/demo/tr:l-text,i-Hello%20World,ff-font-folder@@font-subfolder@@my-custom-font.ttf,fs-72,co-FFF000,l-end/default-image.jpg
Non-English character support
You can overlay text in any language with custom fonts, for example.
List of supported text transformations in text layers
Parameter | Description |
---|---|
w | The maximum width (in pixels) of the overlaid text on the image. The text is wrapped so that any words in a line that go beyond the given width are sent to the next line. The height of the text box is calculated automatically based on the total number of lines. It can also accept arithmetic expressions such as bw_mul_0.2 , or bh_div_2 . Learn more about arithmetic expressions here. |
fs | It is used to specify the font size. It can also accept arithmetic expressions such as bw_mul_0.2 , or bh_div_20 . Learn more about arithmetic expressions here. |
ff | It is used to specify the font of the overlaid text on the image. You can choose any font from this list or use a custom font. |
co | It is used to specify the color and transparency of the overlaid text on the image. It accepts RGB Hex Codes (e.g. FF0000 ), or RGBA Codes (e.g. FFAABB50 ), or color names (e.g. red ). If you specify an 8-character background, the last two characters must be a number between 00 and 99 , which indicate the opacity level of the background. 00 represents an opacity level of 0.00 , 01 represents an opacity level of 0.01 , and so on. |
ia | Inner alignment. Accepts left , right , and center . The default value is center . |
pa | It is used to specify the padding around the overlaid text on the image. Supports any positive integer or a set of positive integers separated by underscores. The set of integers follows CSS shorthand order for determining the padding along each side of the overlay. e.g. 10 , 10_20 , 10_20_30 or 10_20_30_40 . It can also accept arithmetic expressions such as bw_mod_5 , or bw_div_20 . Learn more about arithmetic expressions here. |
al | It is used to specify the transparency level of the overlaid text layer. Supports integers from 1 to 9 . |
tg | Typography. Supports bold b , italics i , and bold with italics b_i . |
bg | It is used to specify the background color in RGB Hex Code (e.g. FF0000 ) or an RGBA Code (e.g. FFAABB50 ), or a color name (e.g. red ). If you specify an 8-character background, the last two characters must be a number between 00 and 99 , which indicate the opacity level of the background. 00 represents an opacity level of 0.00 , 01 represents an opacity level of 0.01 , and so on. |
r | It is used to control the radius of the corner. To get a circle or oval shape, set the value to max . |
lh | It is used to specify the line height(spacing) of the text. It will come into effect only if the text wraps over multiple lines. Accepts integer values representing line height in points. It can also accept arithmetic expressions such as bw_mul_0.2 , or bh_div_20 . Learn more about arithmetic expressions here. |
Add solid color blocks over image
You can add a solid color block over a base image using the following example.
Syntax for solid color block overlay
Use i-ik_canvas
with the bg
parameter to add a solid color block overlay on an image.
https://ik.imagekit.io/demo/base-image.jpg?tr=l-image,i-ik_canvas,bg-FF0000,w-300,h-100,l-end
For example, let's add a solid red color box on an image.
You can also control the position of the solid color overlay using lx
and ly
parameters. Learn more about positional parameters.
Apply transformation on solid color overlay
The following transformation parameters are supported on the solid color block overlay inside a layer.
Parameter | Description |
---|---|
w | Width of solid color block. It can also accept arithmetic expressions such as bw_div_2 , or bw_mul_0.8 . Learn more about arithmetic expressions here. |
h | Height of solid color block. It can also accept arithmetic expressions such as bh_div_2 , or bh_mul_0.8 . Learn more about arithmetic expressions here. |
bg | It is used to specify the color of the block in RGB Hex Code (e.g. FF0000 ), or an RGBA Code (e.g. FFAABB50 ), or a color name (e.g. red ). If you specify an 8-character background, the last two characters must be a number between 00 and 99 , which indicates the opacity level of the background. 00 represents an opacity level of 0.00 , 01 represents an opacity level of 0.01 , and so on. |
al | It is used to specify the transparency level of the overlaid solid color layer. Supports integers from 1 to 9 . |
r | It is used to control the radius of the corner. To get a circle or oval shape, set the value to max . |
e-gradient | It is used to add a linear gradient overlay over an input image. The direction, from color, to color, and the stop point of the gradient can be varied using the following parameters - ld , from , to and sp . e.g. e-gradient-<linear-direction>_<from-color>_<to-color>_<stop-point> (or simply e-gradient to let the gradient take on default values). Learn more about the gradient effect and its parameters here. |
If both bg
and al
are set in a single transformation and bg
has an alpha component, then that value is used to set solid color background transparency. Otherwise, al
value is used. If bg
is set to a standard color name (e.g. blue
), then the al
value is ignored.
Supported text font list
ImageKit.io currently supports the following fonts out of the box.
Font | Support for Bold | Support for Italics |
---|---|---|
AbrilFatFace | No | No |
Amaranth | Yes | Yes |
Arvo | Yes | Yes |
Audiowide | No | No |
Chivo | Yes | Yes |
Crimson Text | Yes | Yes |
exo | Yes | Yes |
Fredoka One | No | No |
Gravitas One | No | No |
Kanit | Yes | Yes |
Lato | Yes | Yes |
Lobster | No | No |
Lora | Yes | Yes |
Monoton | No | No |
Montserrat | Yes | Yes |
PT Mono | No | No |
PT_Serif | Yes | Yes |
Open Sans | Yes | Yes |
Roboto | Yes | Yes |
Old Standard | Yes | Yes |
Ubuntu | Yes | Yes |
Vollkorn | Yes | Yes |
Besides this you can use any custom font by uploading the font file in your media library and passing its path in the ff
parameter in a text layer. See custom font example here.