⌨️ Added a type for image stats
This commit is contained in:
@@ -4,6 +4,7 @@ const leven = require("leven");
|
||||
import path from "path";
|
||||
import { isNull, reject } from "lodash";
|
||||
import { logger } from "./logger.utils";
|
||||
import { ISharpResizedImageStats } from "threetwo-ui-typings";
|
||||
|
||||
export const extractMetadataFromImage = async (
|
||||
imageFilePath: string
|
||||
@@ -21,35 +22,20 @@ export const resizeImage = async (
|
||||
outputPath: string,
|
||||
newWidth: number,
|
||||
newHeight?: number
|
||||
): Promise<unknown> => {
|
||||
return await sharp(imageFile)
|
||||
.resize(newWidth)
|
||||
.toFile(`${outputPath}`, (err, info) => {
|
||||
if (err) {
|
||||
logger.error("Failed to resize image:");
|
||||
logger.error(err);
|
||||
return err;
|
||||
}
|
||||
): Promise<ISharpResizedImageStats> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
sharp(imageFile)
|
||||
.resize(newWidth)
|
||||
.toFile(`${outputPath}`, (err, info) => {
|
||||
if (err) {
|
||||
logger.error("Failed to resize image:");
|
||||
logger.error(err);
|
||||
reject(err);
|
||||
}
|
||||
|
||||
logger.info("Image file resized with the following parameters:");
|
||||
logger.info(info);
|
||||
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")
|
||||
}
|
||||
logger.info("Image file resized with the following parameters:");
|
||||
logger.info(info);
|
||||
resolve(info);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user