Could someone explain how transformations work in relation to nextjs + changing domain?
Hi, using workers to host my nextjs site through opennext, and attempting to use cloudflare images for cdn, have the following config below. Images are loaded using the nextjs image component as PNG. Had two questions
1. the images themselves https://nyoom.engineering/, https://nyoom.engineering/cdn-cgi/image/width=1080,slow-connection-quality=40,format=avif,fit=scale-down,metadata=none/caida/ries-t.png, are still png, I was under the impression that transformations would convert my images on cloudflare's behalf and deliver the right resolution/compression/etc., is that correct?
2. is it posible to change
/cdn-cgi/image
to cdn.nyoom.engineer/static
via redirect or similar?
3. what is the difference between imagedelivery.net
address and what is being done above? when do I use the image delivery URL
Thanks, can attach code if needed
3 Replies
Support AI
I'll address your questions one by one.
1. According to the Cloudflare documentation, the
cdn-cgi
image proxy does support image transformations, including format conversion. However, it seems that the format=avif
parameter in your URL is not being applied. This might be due to the fact that the format
parameter only works if the client's browser supports the specified format. You can try adding the format=auto
parameter to let Cloudflare automatically choose the best format based on the client's browser capabilities.
Source: Cloudflare Images: Serve images through custom domains
2. Yes, it is possible to change the /cdn-cgi/image
path to a custom path like cdn.nyoom.engineer/static
using a URL rewrite. You can use Cloudflare's Transform Rules to achieve this. You can create a rule that rewrites the URL from /cdn-cgi/image
to cdn.nyoom.engineer/static
.
Source: Cloudflare Reference Architecture: Optimizing Image Delivery with Cloudflare Image Resizing and R2
3. The imagedelivery.net
address is a default URL provided by Cloudflare Images for serving images. It is used when you don't have a custom domain set up. The URL format is https://imagedelivery.net/<ACCOUNT_HASH>/<IMAGE_ID>/<VARIANT_NAME>
. In your case, you are using a custom domain (nyoom.engineering
) and the cdn-cgi
image proxy, which is why you don't need to use the imagedelivery.net
address.
Source: Cloudflare Images: Serve uploaded images
I hope this helps clarify things! Let me know if you have any further questions.Sources
Feedback
Feedback has been submitted! Thank you :)
This is an AI generated response, it may not be 100% accurate. Please validate the output. You can ask followups by replying to this message or mentioning me.
Still confused on the first one, as the parameters are present in the url itself so they are being passed somewhere, where I don't know
https://developers.cloudflare.com/images/transform-images/transform-via-url/
It is applying something because the blur function does work https://nyoom.engineering/cdn-cgi/image/width=1080,slow-connection-quality=40,format=avif,fit=scale-down,metadata=none,blur=50/caida/ries-t.png
I'm just confused on how the quality and format are handled?
Cloudflare Docs
Transform via URL
You can convert and resize images by requesting them via a specially-formatted URL. This way you do not need to write any code, only change HTML markup of your website to use the new URLs. The format is: