function loadImage(src) {
  return new Promise((resolve, reject) => {
    const img = new Image();
    img.addEventListener('load', () => resolve(img));
    img.addEventListener('error', () => reject(new Error('load failed')));
    img.src = src;
  });
}
@param {string} src The image source URL.
@return {Promise<HTMLImageElement>} Resolves with the loaded image.