🛣 Levenshtein distance between images WIP
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
const sharp = require("sharp");
|
||||
const imghash = require("imghash");
|
||||
const leven = require("leven");
|
||||
import path from "path";
|
||||
import { isNull, reject } from "lodash";
|
||||
import { logger } from "./logger.utils";
|
||||
|
||||
export const extractMetadataFromImage = async (
|
||||
@@ -32,3 +36,20 @@ export const resizeImage = async (
|
||||
return info;
|
||||
});
|
||||
};
|
||||
|
||||
export const calculateLevenshteinDistance = async (
|
||||
imagePath1: string,
|
||||
imagePath2: string
|
||||
): Promise<Record<string, unknown>> => {
|
||||
console.log("AGANTUK", imagePath1)
|
||||
const hash1 = await imghash.hash(imagePath1);
|
||||
const hash2 = await imghash.hash(imagePath2);
|
||||
console.log("HASHISH", hash1)
|
||||
if (!isNull(hash1) && !isNull(hash2)) {
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve({ levenshteinDistance: leven(hash1, hash2) });
|
||||
});
|
||||
} else {
|
||||
reject("Can't calculate the Levenshtein distance")
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user