App for Cloudflare® Pro

App for Cloudflare® Pro 1.8.9

How to convert all R2 images to webp?

sjamaan

New member
I have moved all images from uploads to the R2 bucket and its on the subdomain. How do I convert it all to webp and have WordPress use the images with new extension?
 
R2 is really just a storage location, there's not a way to convert things on R2 outside of downloading an individual image, converting it and uploading the new image. The plugin does have the ability to convert an uploaded image to webp on the fly, but it really only applies to new images (it doesn't do anything to existing images).

There's also the issue of the historical (non-webp) URLs changing, so if you change the URLs of historical images to have a different extension, you will need to go back and update anywhere you referenced them. You *could* get away with doing redirects (redirecting the old URL to the new) though.

Basically the plugin doesn't go back and do image format changes on historical images, only newly uploaded images (if you enable that option). I suspect there probably is going to be some plugins out there that do exactly that (update existing media to a new image format).
 
Thanks! That's indeed one reason why I asked. I don't want to break the images.
CF has a service CloudFlare Images that supports Transform.
It would be nice if this plugin would transform old images and update the media URL's in WP.
 
Thanks! That's indeed one reason why I asked. I don't want to break the images.
CF has a service CloudFlare Images that supports Transform.
It would be nice if this plugin would transform old images and update the media URL's in WP.
Ya, it wouldn't be particularly hard to do the transforms on the old images, the bigger problem is we don't know all the possible places the old URLs may have been used/referenced. If they were only referenced using the image block in the editor, they would update automatically. It's just the situation where people are directly referencing the images (it's the same problem when migrating old images to R2).

Again, it wouldn't be hard to do from a code standpoint, I'm just not sure if going down the road of doing things like that (which really aren't related to Cloudflare or Cloudflare services) is the most appropriate thing to add in a Cloudflare plugin since it's really not related to Cloudflare. I had the same thought about the option to convert incoming images to webp, but that did end up becoming an option anyway. That's my only real concern... do we really want to go down the road of adding a lot of non-Cloudflare things to a Cloudflare plugin, that's all. It probably makes more logical sense to have it be it's own plugin honestly (even if you just install it, run it and then uninstall it after it's done).
 
I recently had a meeting with CF staff in order to speed up delivery of images and after evaluating my site they advised to add their new CloudFlare Images service in order to serve the most efficient flexible variant of the image. (with or without R2)

To do so I either needed to upload images via API or trough R2. I opted for r2 because your plugin makes that possible. I have not yet fully grasped the workings of CF Images service, but it seems to me that a plugin for this CF service would probably be useful.
 
Ya... the Cloudflare Images service will work (and most certainly will be the easier path). It basically will take your existing images as they are requested and transform them into different formats on the fly. It's actually a pretty good service when someone doesn't want to (or can't for whatever reason) update old images to new formats. The nice thing about it is your original URLs (even with legacy extensions like jpg or png) stay intact.

In your particular case, how many old images are you dealing with roughly?
 
About 2800 images. Not counting the resized variants.
So not talking about tens of millions or something. Personally, with that number, I'd probably go the route of doing the image format changes on my end rather than have Cloudflare do it (and redo it every month... they bill for number of images transformed each month). And then put in place the Redirect Rules so I don't have to know (and update) every place the old URLs were referenced.

It also depends on the types of images... not all images are smaller with webp (in particular jpeg images are sometimes actually *bigger* when you convert them to webp). So honestly, sometimes converting everything to webp just for sake of converting isn't always the best thing to do. Again, it depends on the source images... but oftentimes the gain is minimal and in some cases it's actually worse.
 
It would suck to go through the hassle of converting all your old images only to find out that you didn't really make them smaller after all that. It might be worthwhile to do a manual test with some of your images just to see if converting them to webp actually makes them smaller in your case.
 
Back
Top