Cloudflare Image Resizing Transform Rule

I am currently trying to integrate Cloudflare image resizing into my application without needing to modify the path of my existing URLs.

I’ve looked through the documentation (https://developers.cloudflare.com/images/transform-images/serve-images-custom-paths/#modify-existing-urls-to-be-compatible-with-transformations-in-images) but haven’t been able to implement it successfully.

My current image URLs paths are:

/assets/images/myimage.png?width=600&height=400

I’ve created a Transform Rule with the following:

Text in Expression Editor:

(http.request.uri.path.extension matches "(jpg)|(jpeg)|(png)|(gif)") and (not (any(http.request.headers["via"][*] contains "image-resizing")))

Text in Path > Rewrite to… > Dynamic:

regex_replace(
  http.request.uri.path,
  "/(.*)\\?width=([0-9]+)&height=([0-9]+)$",
  "/cdn-cgi/image/width=${2},height=${3}/${1}"
)

Image Transformations (and flexible variants) are enabled on my zone file and I am on the Enterprise plan.

Any help would be much appreciated!

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