Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/constants/supportedTransforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export const supportedTransforms: { [key: string]: string } = {
lossless: "lo",
colorProfile: "cp",
metadata: "md",
density: "dn",
opacity: "o",
trim: "t",
zoom: "z",
Expand Down
12 changes: 11 additions & 1 deletion src/interfaces/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1420,7 +1420,7 @@ export interface Transformation {
*
* - `co-color` - Color to apply (e.g., `red`, `blue`, `FF0022`). Default is gray
* color.
* - `in-intensity` - Intensity of the color (0-100). Default is 35. See
* - `in-intensity` - Intensity of the color (0-100). Default is 100. See
* [Colorize](https://imagekit.io/docs/effects-and-enhancements#colorize---e-colorize).
*/
colorize?: string;
Expand Down Expand Up @@ -1468,6 +1468,16 @@ export interface Transformation {
*/
defaultImage?: string;

/**
* Sets the output image density in dots per inch (DPI). Accepts an integer from 1
* to 1200 or an arithmetic expression using the `idn` variable, such as
* `idn_mul_2`. For raster images, this updates density metadata without changing
* dimensions. For vector images, it controls the DPI used during rasterization.
* Cannot be used inside layers. See
* [Density](https://imagekit.io/docs/image-optimization#density---dn).
*/
density?: number | string;

/**
* Distorts the shape of an image. Supports two modes:
*
Expand Down
3 changes: 2 additions & 1 deletion test-app/tests/basic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1255,6 +1255,7 @@ test.describe("URL generation", () => {
trim: 5,
metadata: true,
colorProfile: true,
density: 72,
defaultImage: "/folder/file.jpg/",
dpr: 3,
x: 10,
Expand Down Expand Up @@ -1297,7 +1298,7 @@ test.describe("URL generation", () => {
});

expect(url).toBe(
`https://ik.imagekit.io/test_url_endpoint/test_path.jpg?tr=h-300,w-400,ar-4-3,q-40,c-force,cm-extract,fo-left,f-jpeg,r-50,bg-A94D34,b-5-A94D34,rt-90,bl-10,n-some_name,pr-true,lo-true,t-5,md-true,cp-true,di-folder@@file.jpg,dpr-3,x-10,y-20,xc-30,yc-40,fl-h,o-0.8,z-2,vc-h264,ac-aac,so-5,eo-15,du-10,sr-1440_1080,e-grayscale,e-upscale,e-retouch,e-genvar,e-dropshadow,e-changebg-prompt-car,e-edit-prompt-make it vintage,e-bgremove,e-contrast,e-shadow-bl-15_st-40_x-10_y-N5,e-sharpen-10,e-usm-2-2-0.8-0.024,e-gradient-from-red_to-white,orig-true,pg-2_4,h-200,w-300,l-image,i-logo.png,l-end,cr-FF0000_50_00FF00,e-colorize-co-red_in-35,e-distort-p-50_50_150_50_150_150_50_150`
`https://ik.imagekit.io/test_url_endpoint/test_path.jpg?tr=h-300,w-400,ar-4-3,q-40,c-force,cm-extract,fo-left,f-jpeg,r-50,bg-A94D34,b-5-A94D34,rt-90,bl-10,n-some_name,pr-true,lo-true,t-5,md-true,cp-true,dn-72,di-folder@@file.jpg,dpr-3,x-10,y-20,xc-30,yc-40,fl-h,o-0.8,z-2,vc-h264,ac-aac,so-5,eo-15,du-10,sr-1440_1080,e-grayscale,e-upscale,e-retouch,e-genvar,e-dropshadow,e-changebg-prompt-car,e-edit-prompt-make it vintage,e-bgremove,e-contrast,e-shadow-bl-15_st-40_x-10_y-N5,e-sharpen-10,e-usm-2-2-0.8-0.024,e-gradient-from-red_to-white,orig-true,pg-2_4,h-200,w-300,l-image,i-logo.png,l-end,cr-FF0000_50_00FF00,e-colorize-co-red_in-35,e-distort-p-50_50_150_50_150_150_50_150`
);
});
});
10 changes: 10 additions & 0 deletions test-app/tests/buildTransformationString.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,14 @@ test.describe("buildTransformationString", () => {
);
expect(result).toBe("l-text,i-Hello,l-end");
});

test("should generate a transformation string for density as a number", async ({ page }) => {
const result = await page.evaluate(() => (window as any).buildTransformationString([{ density: 72 }]));
expect(result).toBe("dn-72");
});

test("should generate a transformation string for density as an arithmetic expression", async ({ page }) => {
const result = await page.evaluate(() => (window as any).buildTransformationString([{ density: "idn_mul_2" }]));
expect(result).toBe("dn-idn_mul_2");
});
});
Loading