You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
New version of the NodeJS SDK for [ImageKit.io](https://imagekit.io) that implements the new APIs and interface for performing different file operations.
4
9
5
10
ImageKit is a complete image optimization and transformation solution that comes with an [image CDN](https://imagekit.io/features/imagekit-infrastructure) and media storage. It can be integrated with your existing infrastructure - storages like AWS S3, web servers, your CDN and custom domain names, allowing you to deliver optimized images in minutes with minimal code changes.
6
11
12
+
##### Table of contents
13
+
*[Installation](#installation)
14
+
*[Initialization](#initialization)
15
+
*[URL generation](#url-generation)
16
+
*[File upload](#file-upload)
17
+
*[File management](#file-management)
18
+
*[Utility functions](#utility-functions)
19
+
*[Support](#support)
20
+
*[Links](#links)
21
+
7
22
## Installation
8
23
9
24
Use the following command to download this module. Use the optional `--save` parameter if you wish to save the dependency in your `package.json` file.
@@ -27,7 +42,7 @@ var imagekit = new ImageKit({
27
42
## Usage
28
43
You can use this NodeJS SDK for 3 different kinds of functions - URL generation, file uploads and file management. The usage of the SDK has been explained below
29
44
30
-
###URL Generation
45
+
## URL Generation
31
46
32
47
**1. Using image path and image hostname or endpoint**
33
48
@@ -195,7 +210,7 @@ The complete list of transformations supported and their usage in ImageKit can b
195
210
196
211
197
212
198
-
###File Upload
213
+
## File Upload
199
214
200
215
The SDK provides a simple interface using the `.upload()` method to upload files to the ImageKit Media Library. It accepts all the parameters supported by the [ImageKit Upload API](https://docs.imagekit.io/imagekit-docs/server-side-file-upload).
201
216
@@ -216,7 +231,7 @@ If the upload fails, `error` will be the same as what is received from ImageKit'
216
231
217
232
218
233
219
-
###File Management
234
+
## File Management
220
235
221
236
The SDK provides a simple interface for all the [media APIs mentioned here](https://docs.imagekit.io/imagekit-docs/media-api) to manage your files. You can use a callback function with all API interfaces. The first argument of the callback function is the error and the second is the result of the API call. Error will be `null` if the API succeeds.
We have included following commonly used utility functions in this package.
317
+
318
+
### Authentication parameter generation
300
319
301
320
In case you are looking to implement client-side file upload, you are going to need a token, expiry timestamp and a valid signature for that upload. The SDK provides a simple method that you can use in your code to generate these authentication parameters for you.
302
321
@@ -317,10 +336,44 @@ Returns
317
336
318
337
Both the `token` and `expire` parameters are optional. If not specified the SDK uses the [uuid](https://www.npmjs.com/package/uuid) package to generate a random token and also generates a valid expiry timestamp internally. The value of the `token` and `expire` used to generate the signature are always returned in the response, no matter if they are provided as an input to this method or not.
319
338
339
+
### Distance calculation between two pHash values
340
+
341
+
Perceptual hashing allows you to constructing a hash value that uniquely identifies an input image based on the contents of an image. [ImageKit.io metadata API](https://docs.imagekit.io/imagekit-docs/metadata-api) returns the pHash value of an image in the response. You can use this value to find a duplicate (or similar) image by calculating distance between pHash value of two images.
342
+
343
+
This SDK exposes `pHashDistance` function to calcualte distance between two pHash values. It accepts two pHash hexadecimal strings and returns a numeric value indicative of the level of difference between the two images.
344
+
345
+
```
346
+
const calculateDistance = () => {
347
+
// asynchronously fetch metadata of two uploaded image files
348
+
// ...
349
+
// Extract pHash strings from both: say 'firstHash' and 'secondHash'
Copy file name to clipboardExpand all lines: constants/errorMessages.js
+6-2Lines changed: 6 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -10,5 +10,9 @@ module.exports = {
10
10
"LIST_FILES_INPUT_MISSING" : {message : "Missing options for list files",help : "If you do not want to pass any parameter for listing, pass an empty object"},
11
11
"MISSING_UPLOAD_DATA" : {message : "Missing data for upload",help : ""},
0 commit comments