23 lines
597 B
TypeScript
23 lines
597 B
TypeScript
export function getImageUrl(url: string) {
|
|
return `${import.meta.env.DIRECTUS_URL}assets/${url}`;
|
|
}
|
|
|
|
export function getImageSize(width: number, height: number, targetMegapixels: number): ResizedImageResponse {
|
|
const originalPixels = width * height;
|
|
const targetPixels = targetMegapixels * 1000 * 1000;
|
|
|
|
if (originalPixels >= targetPixels) {
|
|
return {
|
|
width,
|
|
height
|
|
}
|
|
}
|
|
|
|
const scale = Math.sqrt(targetPixels / originalPixels);
|
|
|
|
return {
|
|
width: Math.round(scale * width),
|
|
height: Math.round(scale * height)
|
|
}
|
|
}
|