How to optimize images that are external?

Hi. I'm using this code

const normalizeSrc = (src: string) => {
  return src.startsWith("/") ? src.slice(1) : src;
};

export default function cloudflareLoader({
  src,
  width,
  quality,
}: { src: string; width: number; quality?: number }) {
  if (process.env.NODE_ENV === "development") {
      return src;
  }
  const params = [`width=${width}`];
  if (quality) {
      params.push(`quality=${quality}`);
  }
  const paramsString = params.join(",");
  
  return `/cgi/image/${paramsString}/${normalizeSrc(src)}
}


besides my local images from the public directory in next.js, i have a dynamic page where the images are coming from a different source

https://data.companyname.com/ppic/test.jpeg

how can i use this in image in the custom loader and optimize it?

at the moment they are not loading at all

thanks
Was this page helpful?