ManagementSystem/TrackingToolWeb/client/src/lib/utils.ts

44 lines
1.1 KiB
TypeScript

/* eslint-disable @typescript-eslint/no-explicit-any */
import { clsx, type ClassValue } from "clsx";
import moment from "moment";
import { twMerge } from "tailwind-merge";
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
export const formatTime = (timeString: string) => {
return moment(timeString).format("DD/MM/YYYY HH:mm:ss");
};
export function capture(videoRef: any, canvasRef: any) {
if (!videoRef.current || !canvasRef.current) return;
const canvas = canvasRef.current;
const video = videoRef.current;
const context = canvas.getContext("2d");
return new Promise((resolve, reject) => {
try {
canvas.width = video.videoWidth;
canvas.height = video.videoHeight;
context.drawImage(video, 0, 0, canvas.width, canvas.height);
canvas.toBlob(
(blob: unknown) => {
if (!blob) {
reject("Không thể tạo blob từ canvas");
return;
}
resolve(blob);
},
"image/jpeg",
0.95 // chất lượng cao
);
} catch (error) {
reject(error);
}
});
}