UNPKG

@oberoncms/plugin-uploadthing

Version:

An Puck component and OberonCMS plugin for embeding uploadthing images

28 lines (27 loc) 680 B
import { imageSize } from "image-size"; async function getImageSize(url, defaultSize = { width: 100, height: 100 }) { const chunks = []; const response = await fetch(url); if (!response.body) { throw new Error("Image not found for size processing"); } const reader = response.body.getReader(); while (true) { const { done, value } = await reader.read(); if (done) { return defaultSize; } chunks.push(value); try { const { width, height } = imageSize(Buffer.concat(chunks)); if (width && height) { return { width, height }; } return defaultSize; } catch (error) { } } } export { getImageSize };