export const getImageMetadata = (imageUrl: string) => new Promise<Record<string, string | number>>((resolve, reject) => {
  const image = new Image();
  image.addEventListener('load', (imageLoadEvent) => {
    const thisImage = imageLoadEvent.currentTarget as HTMLImageElement;
    const metadata = {
      width: thisImage.naturalWidth,
      height: thisImage.naturalHeight,
    };
    image.remove();
    resolve(metadata);
  });

  image.addEventListener('error', () => {
    reject();
    image.remove();
  });

  image.src = imageUrl;
});
