Refactor: remove AGPL imgly dependency and migrate background removal to python backend
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
export async function detectMediaDimensionsAndAspect(
|
||||
url: string,
|
||||
type: 'video' | 'image'
|
||||
): Promise<{ width: number; height: number; format: 'video' | 'image'; aspect: string }> {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (type === 'image') {
|
||||
const img = new Image();
|
||||
img.onload = () => {
|
||||
resolve({
|
||||
width: img.width,
|
||||
height: img.height,
|
||||
format: 'image',
|
||||
aspect: `${img.width}:${img.height}`,
|
||||
});
|
||||
};
|
||||
img.onerror = () => reject(new Error('Failed to load image to detect dimensions.'));
|
||||
img.src = url;
|
||||
} else {
|
||||
const video = document.createElement('video');
|
||||
video.onloadedmetadata = () => {
|
||||
resolve({
|
||||
width: video.videoWidth,
|
||||
height: video.videoHeight,
|
||||
format: 'video',
|
||||
aspect: `${video.videoWidth}:${video.videoHeight}`,
|
||||
});
|
||||
};
|
||||
video.onerror = () => reject(new Error('Failed to load video to detect dimensions.'));
|
||||
video.src = url;
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user