Skip to content

Commit e1e5abf

Browse files
committed
feat: update README to enhance SDK description and usage examples
1 parent 08a5744 commit e1e5abf

File tree

1 file changed

+12
-199
lines changed

1 file changed

+12
-199
lines changed

README.md

Lines changed: 12 additions & 199 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
1-
# Image Kit TypeScript API Library
1+
# ImageKit.io Node.js SDK
22

33
[![NPM version](<https://img.shields.io/npm/v/@imagekit/nodejs.svg?label=npm%20(stable)>)](https://npmjs.org/package/@imagekit/nodejs) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/@imagekit/nodejs)
44

5-
This library provides convenient access to the Image Kit REST API from server-side TypeScript or JavaScript.
5+
This SDK provides everything you need to integrate ImageKit into your server-side applications. Beyond convenient access to the ImageKit REST API, the library includes:
6+
7+
- **URL Builder & Transformations** - Helper functions to generate optimized image and video URLs with real-time transformations.
8+
- **URL Signing** - Built-in support for generating signed URLs for secure content delivery.
9+
- **Authentication Helpers** - Generate authentication parameters for secure client-side file uploads.
10+
- **Webhook Verification** - Utilities to verify webhook signatures for secure event handling.
611

712
The REST API documentation can be found on [imagekit.io](https://imagekit.io/docs/api-reference). The full API of this library can be found in [api.md](api.md).
813

14+
Refer to the ImageKit official [quick start guide](https://imagekit.io/docs/integration/nodejs) for more details on using the SDK.
15+
16+
If you are looking to integrate file uploads on the client-side, use one of the [client-side SDKs](https://imagekit.io/docs/quick-start-guides#front-end) for easy integration.
17+
918
## Installation
1019

1120
```sh
@@ -32,7 +41,7 @@ const response = await client.files.upload({
3241
fileName: 'file-name.jpg',
3342
});
3443

35-
console.log(response.videoCodec);
44+
console.log(response);
3645
```
3746

3847
### Request & Response types
@@ -85,202 +94,6 @@ await client.files.upload({ file: await toFile(Buffer.from('my bytes'), 'file'),
8594
await client.files.upload({ file: await toFile(new Uint8Array([0, 1, 2]), 'file'), fileName: 'fileName' });
8695
```
8796

88-
## URL generation
89-
90-
The ImageKit SDK provides a powerful `helper.buildSrc()` method for generating optimized image and video URLs with transformations. Here are examples ranging from simple URLs to complex transformations with overlays and signed URLs.
91-
92-
### Basic URL generation
93-
94-
Generate a simple URL without any transformations:
95-
96-
```ts
97-
import ImageKit from '@imagekit/nodejs';
98-
99-
const client = new ImageKit({
100-
privateKey: process.env['IMAGEKIT_PRIVATE_KEY']
101-
});
102-
103-
// Basic URL without transformations
104-
const url = client.helper.buildSrc({
105-
urlEndpoint: 'https://ik.imagekit.io/your_imagekit_id',
106-
src: '/path/to/image.jpg',
107-
});
108-
// Result: https://ik.imagekit.io/your_imagekit_id/path/to/image.jpg
109-
```
110-
111-
### URL generation with transformations
112-
113-
Apply common transformations like resizing, cropping, and format conversion:
114-
115-
```ts
116-
// URL with basic transformations
117-
const transformedUrl = client.helper.buildSrc({
118-
urlEndpoint: 'https://ik.imagekit.io/your_imagekit_id',
119-
src: '/path/to/image.jpg',
120-
transformation: [
121-
{
122-
width: 400,
123-
height: 300,
124-
crop: 'maintain_ratio',
125-
quality: 80,
126-
format: 'webp',
127-
},
128-
],
129-
});
130-
// Result: https://ik.imagekit.io/your_imagekit_id/path/to/image.jpg?tr=w-400,h-300,c-maintain_ratio,q-80,f-webp
131-
```
132-
133-
### URL generation with image overlay
134-
135-
Add image overlays to your base image:
136-
137-
```ts
138-
// URL with image overlay
139-
const imageOverlayUrl = client.helper.buildSrc({
140-
urlEndpoint: 'https://ik.imagekit.io/your_imagekit_id',
141-
src: '/path/to/base-image.jpg',
142-
transformation: [
143-
{
144-
width: 500,
145-
height: 400,
146-
overlay: {
147-
type: 'image',
148-
input: '/path/to/overlay-logo.png',
149-
position: {
150-
x: 10,
151-
y: 10,
152-
},
153-
transformation: [
154-
{
155-
width: 100,
156-
height: 50,
157-
},
158-
],
159-
},
160-
},
161-
],
162-
});
163-
// Result: URL with image overlay positioned at x:10, y:10
164-
```
165-
166-
### URL generation with text overlay
167-
168-
Add customized text overlays:
169-
170-
```ts
171-
// URL with text overlay
172-
const textOverlayUrl = client.helper.buildSrc({
173-
urlEndpoint: 'https://ik.imagekit.io/your_imagekit_id',
174-
src: '/path/to/base-image.jpg',
175-
transformation: [
176-
{
177-
width: 600,
178-
height: 400,
179-
overlay: {
180-
type: 'text',
181-
text: 'Sample Text Overlay',
182-
position: {
183-
x: 50,
184-
y: 50,
185-
focus: 'center',
186-
},
187-
transformation: [
188-
{
189-
fontSize: 40,
190-
fontFamily: 'Arial',
191-
fontColor: 'FFFFFF',
192-
typography: 'b', // bold
193-
},
194-
],
195-
},
196-
},
197-
],
198-
});
199-
// Result: URL with bold white Arial text overlay at center position
200-
```
201-
202-
### URL generation with multiple overlays
203-
204-
Combine multiple overlays for complex compositions:
205-
206-
```ts
207-
// URL with multiple overlays (text + image)
208-
const multipleOverlaysUrl = client.helper.buildSrc({
209-
urlEndpoint: 'https://ik.imagekit.io/your_imagekit_id',
210-
src: '/path/to/base-image.jpg',
211-
transformation: [
212-
{
213-
width: 800,
214-
height: 600,
215-
overlay: {
216-
type: 'text',
217-
text: 'Header Text',
218-
position: { x: 20, y: 20 },
219-
transformation: [{ fontSize: 30, fontColor: '000000' }],
220-
},
221-
},
222-
{
223-
overlay: {
224-
type: 'image',
225-
input: '/watermark.png',
226-
position: { focus: 'bottom_right' },
227-
transformation: [{ width: 100, opacity: 70 }],
228-
},
229-
},
230-
],
231-
});
232-
// Result: URL with text overlay at top-left and semi-transparent watermark at bottom-right
233-
```
234-
235-
### Signed URLs for secure delivery
236-
237-
Generate signed URLs that expire after a specified time for secure content delivery:
238-
239-
```ts
240-
// Generate a signed URL that expires in 1 hour (3600 seconds)
241-
const signedUrl = client.helper.buildSrc({
242-
urlEndpoint: 'https://ik.imagekit.io/your_imagekit_id',
243-
src: '/private/secure-image.jpg',
244-
transformation: [
245-
{
246-
width: 400,
247-
height: 300,
248-
quality: 90,
249-
},
250-
],
251-
signed: true,
252-
expiresIn: 3600, // URL expires in 1 hour
253-
});
254-
// Result: URL with signature parameters (?ik-t=timestamp&ik-s=signature)
255-
256-
// Generate a signed URL that doesn't expire
257-
const permanentSignedUrl = client.helper.buildSrc({
258-
urlEndpoint: 'https://ik.imagekit.io/your_imagekit_id',
259-
src: '/private/secure-image.jpg',
260-
signed: true,
261-
// No expiresIn means the URL won't expire
262-
});
263-
// Result: URL with signature parameter (?ik-s=signature)
264-
```
265-
266-
### Authentication parameters for client-side uploads
267-
268-
Generate authentication parameters for secure client-side file uploads:
269-
270-
```ts
271-
// Generate authentication parameters for client-side uploads
272-
const authParams = client.helper.getAuthenticationParameters();
273-
console.log(authParams);
274-
// Result: { token: 'uuid-token', expire: timestamp, signature: 'hmac-signature' }
275-
276-
// Generate with custom token and expiry
277-
const customAuthParams = client.helper.getAuthenticationParameters('my-custom-token', 1800);
278-
console.log(customAuthParams);
279-
// Result: { token: 'my-custom-token', expire: 1800, signature: 'hmac-signature' }
280-
```
281-
282-
These authentication parameters can be used in client-side upload forms to securely upload files without exposing your private API key.
283-
28497
## Handling errors
28598

28699
When the library is unable to connect to the API,

0 commit comments

Comments
 (0)