Gathering detailed insights and metrics for imagekit-javascript
Gathering detailed insights and metrics for imagekit-javascript
Gathering detailed insights and metrics for imagekit-javascript
Gathering detailed insights and metrics for imagekit-javascript
imagekit
Offical NodeJS SDK for ImageKit.io integration
@imagekit/javascript
ImageKit Javascript SDK
imagekit-media-library-widget
Javascript plugin for using Imagekit Media Library Widget
@imagekit/vue
[<img width="250" alt="ImageKit.io" src="https://raw.githubusercontent.com/imagekit-developer/imagekit-javascript/master/assets/imagekit-light-logo.svg"/>](https://imagekit.io)
npm install imagekit-javascript
Typescript
Module System
Node Version
NPM Version
JavaScript (63.93%)
TypeScript (36.07%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
86 Stars
344 Commits
26 Forks
5 Watchers
19 Branches
16 Contributors
Updated on Jun 30, 2025
Latest Version
4.0.1
Package Id
imagekit-javascript@4.0.1
Unpacked Size
223.59 kB
Size
44.62 kB
File Count
38
NPM Version
6.14.16
Node Version
12.22.12
Published on
Apr 01, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
26
A lightweight JavaScript SDK for generating image and video URLs with transformations, and for uploading files directly from the browser to ImageKit. This SDK is intended for use in the browser only. For Node.js, please refer to our official Node.js SDK.
Install the SDK via npm:
1npm install imagekit-javascript --save 2# or 3yarn add imagekit-javascript
Then import ImageKit:
1import ImageKit from "imagekit-javascript"; 2// or with CommonJS: 3const ImageKit = require("imagekit-javascript");
You can also use the global CDN:
Download a specific version:
https://unpkg.com/imagekit-javascript@1.3.0/dist/imagekit.min.js
Or for the latest version, remove the version number (don't use in production as it may break your code if a new major version is released):
https://unpkg.com/imagekit-javascript/dist/imagekit.min.js
And include it in your HTML:
1<script type="text/javascript" src="https://unpkg.com/imagekit-javascript/dist/imagekit.min.js"></script>
To use the SDK, initialize it with your ImageKit URL endpoint. You can get the URL endpoint here and your public API key from the developer section:
1var imagekit = new ImageKit({
2 urlEndpoint: "https://ik.imagekit.io/your_imagekit_id", // Required
3 transformationPosition: "query", // Optional, defaults to "query"
4 publicKey: "your_public_api_key", // Optional, required only for client-side file uploads
5});
Note: Never include your private API key in client-side code. The SDK will throw an error if you do.
Option | Description | Example |
---|---|---|
urlEndpoint | Required. Your ImageKit URL endpoint or custom domain. | urlEndpoint: "https://ik.imagekit.io/your_id" |
transformationPosition | Optional. Specifies whether transformations are added as URL path segments (path ) or query parameters (query ). The default is query , which allows you to perform wildcard purges and remove all generated transformations from the CDN cache. | transformationPosition: "query" |
publicKey | Optional. Your public API key for client-side uploads. | publicKey: "your_public_api_key" |
The SDK’s .url()
method enables you to generate optimized image and video URLs with a variety of transformations.
The method accepts an object with the following parameters:
Option | Description | Example |
---|---|---|
path | The relative path of the image. Either src or path must be provided. | "/path/to/image.jpg" |
src | The full URL of an image already mapped to ImageKit. Either src or path must be provided. | "https://ik.imagekit.io/your_imagekit_id/path/to/image.jpg" |
transformation | An array of objects specifying the transformations to be applied in the URL. Each object contains key-value pairs representing transformation parameters. See supported transformations. | [ { width: 300, height: 400 } ] |
queryParameters | Additional query parameters to be appended to the URL. | { v: 1 } |
Optionally, you can include transformationPosition
and urlEndpoint
in the object to override the initialization settings for a specific .url()
call.
A simple height and width transformation:
1var imageURL = imagekit.url({ 2 path: "/default-image.jpg", 3 urlEndpoint: "https://ik.imagekit.io/your_imagekit_id/endpoint/", 4 transformation: [{ 5 height: 300, 6 width: 400 7 }] 8});
Result Example:
https://ik.imagekit.io/your_imagekit_id/endpoint/default-image.jpg?tr=h-300,w-400
SDK automatically generates the URL based on the provided parameters. The generated URL includes the base URL, path, and transformation parameters.
Apply multiple transformations by passing an array:
1var imageURL = imagekit.url({ 2 path: "/default-image.jpg", 3 transformation: [{ 4 height: 300, 5 width: 400 6 }, { 7 rotation: 90 8 }], 9});
Result Example:
https://ik.imagekit.io/your_imagekit_id/default-image.jpg?tr=h-300,w-400:rt-90
Text Overlay Example:
1var imageURL = imagekit.url({ 2 src: "https://ik.imagekit.io/your_imagekit_id/default-image.jpg", 3 transformation: [{ 4 width: 400, 5 height: 300, 6 overlay: { 7 text: "Imagekit", 8 fontSize: 50, 9 color: "red", 10 position: { 11 x: 10, 12 y: 20 13 } 14 } 15 }] 16});
Image Overlay Example:
1var imageURL = imagekit.url({ 2 src: "https://ik.imagekit.io/your_imagekit_id/default-image.jpg", 3 transformation: [{ 4 width: 400, 5 height: 300, 6 overlay: { 7 type: "image", 8 input: "logo.png", 9 transformation: [{ 10 width: 100, 11 border: "10_CDDC39" 12 }], 13 position: { 14 focus: "top_left" 15 } 16 } 17 }] 18});
Video Overlay Example:
1var videoOverlayURL = imagekit.url({ 2 src: "https://ik.imagekit.io/your_imagekit_id/base-video.mp4", 3 transformation: [{ 4 overlay: { 5 type: "video", 6 input: "overlay-video.mp4", 7 position: { 8 x: "10", 9 y: "20" 10 }, 11 timing: { 12 start: 5, 13 duration: 10 14 } 15 } 16 }] 17});
Subtitle Overlay Example:
1var subtitleOverlayURL = imagekit.url({ 2 src: "https://ik.imagekit.io/your_imagekit_id/base-video.mp4", 3 transformation: [{ 4 overlay: { 5 type: "subtitle", 6 input: "subtitle.vtt", 7 transformation: [{ 8 fontSize: 16, 9 fontFamily: "Arial" 10 }], 11 position: { 12 focus: "bottom" 13 }, 14 timing: { 15 start: 0, 16 duration: 5 17 } 18 } 19 }] 20});
Solid Color Overlay Example:
1var solidColorOverlayURL = imagekit.url({ 2 src: "https://ik.imagekit.io/your_imagekit_id/base-image.jpg", 3 transformation: [{ 4 overlay: { 5 type: "solidColor", 6 color: "FF0000", 7 transformation: [{ 8 width: 100, 9 height: 50, 10 alpha: 5 11 }], 12 position: { x: 20, y: 20 } 13 } 14 }] 15});
ImageKit supports various overlay types, including text, image, video, subtitle, and solid color overlays. Each overlay type has specific configuration options to customize the overlay appearance and behavior. To learn more about how overlays work, refer to the ImageKit documentation.
The table below outlines the available overlay configuration options:
Option | Description | Example |
---|---|---|
type | Specifies the type of overlay. Supported values: text , image , video , subtitle , solidColor . | type: "text" |
text | (For text overlays) The text content to display. | text: "ImageKit" |
input | (For image, video, or subtitle overlays) Relative path to the overlay asset. | input: "logo.png" or input: "overlay-video.mp4" |
color | (For solidColor overlays) RGB/RGBA hex code or color name for the overlay color. | color: "FF0000" |
encoding | Accepted values: auto , plain , base64 . Check this for more details. | encoding: "auto" |
transformation | An array of transformation objects to style the overlay. - Text Overlay Transformations - Subtitle Overlay Transformations - Image and video overlays support most transformations. See ImageKit docs for more details. | transformation: [{ fontSize: 50 }] |
position | Sets the overlay’s position relative to the base asset. Accepts an object with x , y , or focus . The focus value can be one of: center , top , left , bottom , right , top_left , top_right , bottom_left , or bottom_right . | position: { x: 10, y: 20 } or position: { focus: "center" } |
timing | (For video base) Specifies when the overlay appears using start , duration , and end (in seconds); if both duration and end are set, duration is ignored. | timing: { start: 5, duration: 10 } |
Overlay encoding options define how the overlay input is converted for URL construction. When set to auto
, the SDK automatically determines whether to use plain text or Base64 encoding based on the input content.
For text overlays:
auto
is used, the SDK checks the text overlay input: if it is URL-safe, it uses the format i-{input}
(plain text); otherwise, it applies Base64 encoding with the format ie-{base64_encoded_input}
.plain
(always use i-{input}
) or base64
(always use ie-{base64}
).For image, video, and subtitle overlays:
@@
when plain
is used.auto
is used, the SDK determines whether to apply plain text or Base64 encoding based on the characters present.plain
or base64
to enforce the desired encoding.Use auto
for most cases to let the SDK optimize encoding, and use plain
or base64
when a specific encoding method is required.
Option | Description | Example |
---|---|---|
width | Specifies the width of the solid color overlay block (in pixels or as an arithmetic expression). | width: 100 |
height | Specifies the height of the solid color overlay block (in pixels or as an arithmetic expression). | height: 50 |
radius | Specifies the corner radius of the solid color overlay block or shape. Can be a number or "max" for circular/oval shapes. | radius: "max" |
alpha | Specifies the transparency level of the solid color overlay. Supports integers from 1 (most transparent) to 9 (least transparent). | alpha: 5 |
Option | Description | Example |
---|---|---|
width | Specifies the maximum width (in pixels) of the overlaid text. The text wraps automatically, and arithmetic expressions are supported (e.g., bw_mul_0.2 or bh_div_2 ). | width: 400 |
fontSize | Specifies the font size of the overlaid text. Accepts a numeric value or an arithmetic expression. | fontSize: 50 |
fontFamily | Specifies the font family of the overlaid text. Choose from the supported fonts or provide a custom font. | fontFamily: "Arial" |
fontColor | Specifies the font color of the overlaid text. Accepts an RGB hex code, an RGBA code, or a standard color name. | fontColor: "FF0000" |
innerAlignment | Specifies the inner alignment of the text when it doesn’t occupy the full width. Supported values: left , right , center . | innerAlignment: "center" |
padding | Specifies the padding around the text overlay. Can be a single integer or multiple values separated by underscores; arithmetic expressions are accepted. | padding: 10 |
alpha | Specifies the transparency level of the text overlay. Accepts an integer between 1 and 9 . | alpha: 5 |
typography | Specifies the typography style of the text. Supported values: b for bold, i for italics, and b_i for bold with italics. | typography: "b" |
background | Specifies the background color of the text overlay. Accepts an RGB hex code, an RGBA code, or a color name. | background: "red" |
radius | Specifies the corner radius of the text overlay. Accepts a numeric value or max for circular/oval shape. | radius: "max" |
rotation | Specifies the rotation angle of the text overlay. Accepts a numeric value for clockwise rotation or a string prefixed with N for counterclockwise rotation. | rotation: 90 |
flip | Specifies the flip option for the text overlay. Supported values: h , v , h_v , v_h . | flip: "h" |
lineHeight | Specifies the line height for multi-line text. Accepts a numeric value or an arithmetic expression. | lineHeight: 1.5 |
Option | Description | Example |
---|---|---|
background | Specifies the subtitle background color using a standard color name, RGB color code, or RGBA color code. | background: "blue" |
fontSize | Sets the font size of subtitle text. | fontSize: 16 |
fontFamily | Sets the font family of subtitle text. | fontFamily: "Arial" |
color | Specifies the font color of subtitle text using standard color name, RGB, or RGBA color code. | color: "FF0000" |
typography | Sets the typography style of subtitle text. Supported values: b , i , b_i . | typography: "b" |
fontOutline | Specifies the font outline for subtitles. Requires an outline width and color separated by an underscore. | fontOutline: "2_blue" |
fontShadow | Specifies the font shadow for subtitles. Requires shadow color and indent separated by an underscore. | fontShadow: "blue_2" |
Background Removal:
1var imageURL = imagekit.url({ 2 path: "/sample-image.jpg", 3 transformation: [{ 4 aiRemoveBackground: true 5 }] 6});
Upscaling:
1var upscaledURL = imagekit.url({ 2 path: "/sample-image.jpg", 3 transformation: [{ 4 aiUpscale: true 5 }] 6});
Drop Shadow:
1var dropShadowURL = imagekit.url({ 2 path: "/sample-image.jpg", 3 transformation: [{ 4 aiDropShadow: "az-45" 5 }] 6});
1var imageURL = imagekit.url({ 2 src: "https://ik.imagekit.io/your_imagekit_id/default-image.jpg", 3 transformation: [{ 4 width: "iw_div_4", 5 height: "ih_div_2", 6 border: "cw_mul_0.05_yellow" 7 }] 8});
The SDK gives a name to each transformation parameter (e.g. height
maps to h
, width
maps to w
). If the property does not match any of the following supported options, it is added as is.
If you want to generate transformations without any modifications, use the raw
parameter.
Check ImageKit transformation documentation for more details.
Transformation Name | URL Parameter |
---|---|
width | w |
height | h |
aspectRatio | ar |
quality | q |
aiRemoveBackground | e-bgremove (ImageKit powered) |
aiRemoveBackgroundExternal | e-removedotbg (Using third party) |
aiUpscale | e-upscale |
aiRetouch | e-retouch |
aiVariation | e-genvar |
aiDropShadow | e-dropshadow |
aiChangeBackground | e-changebg |
crop | c |
cropMode | cm |
x | x |
y | y |
xCenter | xc |
yCenter | yc |
focus | fo |
format | f |
radius | r |
background | bg |
border | b |
rotation | rt |
blur | bl |
named | n |
dpr | dpr |
progressive | pr |
lossless | lo |
trim | t |
metadata | md |
colorProfile | cp |
defaultImage | di |
original | orig |
videoCodec | vc |
audioCodec | ac |
grayscale | e-grayscale |
contrastStretch | e-contrast |
shadow | e-shadow |
sharpen | e-sharpen |
unsharpMask | e-usm |
gradient | e-gradient |
flip | fl |
opacity | o |
zoom | z |
page | pg |
startOffset | so |
endOffset | eo |
duration | du |
streamingResolutions | sr |
overlay | Generates the correct layer syntax for image, video, text, subtitle, and solid color overlays. |
raw | The string provided in raw will be added in the URL as is. |
If you specify a transformation parameter that is not explicitly supported by the SDK, it is added “as-is” in the generated URL. This provides flexibility for using new or custom transformations without waiting for an SDK update.
For example:
1var imageURL = imagekit.url({ 2 path: "/test_path.jpg", 3 transformation: [{ 4 newparam: "cool" 5 }] 6}); 7// Generated URL: https://ik.imagekit.io/test_url_endpoint/test_path.jpg?tr=newparam-cool
The SDK offers a simple interface via the .upload()
method to upload files to the ImageKit Media Library. This method requires the following:
Before invoking the upload, generate the necessary security parameters as per the ImageKit Upload API documentation.
Option | Description | Example |
---|---|---|
file | The file content to be uploaded. Accepts binary, base64 string, or URL. | file: fileInput.files[0] |
fileName | The name to assign to the uploaded file. Supports alphanumeric characters, dot, underscore, and dash. | fileName: "myImage.jpg" |
signature | HMAC-SHA1 digest computed using the private API key. Must be calculated on the server side. | signature: "generated_signature" |
token | A unique token to prevent duplicate upload retries. Typically a V4 UUID or similar unique string. | token: "unique_upload_token" |
expire | Unix timestamp (in seconds) indicating the signature expiry time (should be within 1 hour). | expire: 1616161616 |
useUniqueFileName | Boolean flag to automatically generate a unique filename if set to true. Defaults to true. | useUniqueFileName: true |
folder | The folder path where the file will be uploaded. Automatically creates nested folders if they don’t exist. | folder: "/images/uploads" |
isPrivateFile | Boolean to mark the file as private, restricting access to the original file URL. Defaults to false. | isPrivateFile: false |
tags | Tags to associate with the file. Can be a comma-separated string or an array of tags. | tags: "summer,holiday" or tags: ["summer","holiday"] |
customCoordinates | Specifies an area of interest in the image formatted as x,y,width,height . | customCoordinates: "10,10,100,100" |
responseFields | Comma-separated list of fields to include in the upload response. | responseFields: "tags,customCoordinates" |
extensions | Array of extension objects for additional image processing. | extensions: [{ name: "auto-tagging" }] |
webhookUrl | URL to which the final status of extension processing will be sent. | webhookUrl: "https://example.com/webhook" |
overwriteFile | Boolean flag indicating whether to overwrite a file if it exists. Defaults to true. | overwriteFile: true |
overwriteAITags | Boolean flag to remove AITags from a file if overwritten. Defaults to true. | overwriteAITags: true |
overwriteTags | Boolean flag that determines if existing tags should be removed when new tags are not provided. Defaults to true when file is overwritten without tags. | overwriteTags: true |
overwriteCustomMetadata | Boolean flag dictating if existing custom metadata should be removed when not provided. Defaults to true under similar conditions as tags. | overwriteCustomMetadata: true |
customMetadata | Stringified JSON or an object containing custom metadata key-value pairs to associate with the file. | customMetadata: {author: "John Doe"} |
transformation | Optional transformation object to apply during the upload process. It follows the same structure as in URL generation. | transformation: { pre: "w-200,h-200", post: [...] } |
xhr | An optional XMLHttpRequest object provided to monitor upload progress. | xhr: new XMLHttpRequest() |
checks | Optional string value for specifying server-side checks to run before file upload. | checks: "file.size' < '1MB'" |
Below is an HTML form example that uses a callback for handling the upload response:
1<form action="#" onsubmit="upload(); return false;"> 2 <input type="file" id="file1" /> 3 <input type="submit" /> 4</form> 5<script src="../dist/imagekit.js"></script> 6<script> 7 var imagekit = new ImageKit({ 8 publicKey: "your_public_api_key", 9 urlEndpoint: "https://ik.imagekit.io/your_imagekit_id", 10 }); 11 12 function upload() { 13 var file = document.getElementById("file1"); 14 imagekit.upload({ 15 file: file.files[0], 16 fileName: "abc1.jpg", 17 token: 'generated_token', 18 signature: 'generated_signature', 19 expire: 'generated_expire' 20 }, function(err, result) { 21 if(err){ 22 console.error(err); 23 } else { 24 console.log(result); 25 } 26 }); 27 } 28</script>
You can also use promises for a cleaner asynchronous approach:
1imagekit.upload({ 2 file: file.files[0], 3 fileName: "abc1.jpg", 4 token: 'generated_token', 5 signature: 'generated_signature', 6 expire: 'generated_expire' 7}).then(result => { 8 console.log(result); 9}).catch(error => { 10 console.error(error); 11});
For a quick demonstration of the SDK features, check the test suite:
For a detailed history of changes, please refer to CHANGELOG.md.
No vulnerabilities found.
Reason
13 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 10
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
Found 0/8 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
license file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
20 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More