How to use Flexible Variants inside Workers?

Documentation says https://developers.cloudflare.com/images/cloudflare-images/transform/flexible-variants/ that there is ability to set Flexible variants options inside Workers with cf object (inside fetch() method I guess)

My questions are:
Is that possible to use this feature for images that uploaded to Cloudflare Images?
If it’s possible, how to use it exactly?

I’ve tried to create a Worker to apply some transformations (for example, 180 degree rotation) on images that are stored at Cloudflare Images
I assumed the Worker code should look like this (hardcoded for brevity, Flexible variants feature is enabled):

export default {
	async fetch(request, env, ctx) {
	    const account_hash = "MY_ACCOUNT_HASH"
            const imageURL = "https://imagedelivery.net/" + account_hash + "/7933cea0-4e74-4c69-9283-36af7358fd00/banner";
            const imageRequest = new Request(imageURL, {
              headers: request.headers
            })

            let options = { cf: { image: {} } }
            options.cf.image.rotate = 180

            return fetch(imageRequest, options)
	},
};

But there’s a catch – the Image Delivery URL must contain a VARIANT_NAME parameter
So my worker returns an image variant provided by fetch() url, without extra transformations
Am I missing something?

Thank you

For Images product, flexible variants only work as URL Format URL format · Cloudflare Image Optimization docs

e.g.

https://imagedelivery.net/" + account_hash + "/7933cea0-4e74-4c69-9283-36af7358fd00/rotate=90

Thanks!
Then I wonder why there’s “Workers” option on every transformation property in the article (https://developers.cloudflare.com/images/cloudflare-images/transform/flexible-variants/)
Any explanations?

looks like this part was copied from image-resizing documentation URL format · Cloudflare Image Optimization docs

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