Cloudflare Page Functions and Image Resizing Not Working

Hello,

I’m having a lot of trouble getting Cloudflare’s Image Resizing feature to work inside a Cloudflare Page function. I have a barebones Astro project with a functions folder that has one hello.js file in it. That file has the following code:

export function onRequest() {
  return fetch(
    "https://images.unsplash.com/photo-1437964706703-40b90bdf563b?q=80&w=3264&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D",
    {
      cf: {
        image: {
          format: "avif",
          width: 200,
        },
      },
    },
  );
}

I’m trying to use Cloudflare’s image resizing within workers as described in the docs. I’ve added a custom domain to this pages project and have enabled image resizing for this zone. Yet, when I visit the /hello path in my browser the image that comes back is unoptimized and it appears that the cf object is being ignored. The response also doesn’t contain the Cf-Resized header described here.

Does image resizing not work within a page function? What have I misunderstood?

Thank you for your help!

1 Like

I encountered the same issue

This topic was automatically closed after 15 days. New replies are no longer allowed.