A hybrid approach to image transforms
Transform in the cloud, serve forever from your own server.
A middle ground made possible with the new Imgix Download Transformer.
— Published on May 26, 2024
As many Craft developers, we've relied on Imgix for cloud-based image transforms for years. Unfortunately, their pricing model changes and aggressive pivot to enterprise over the last couple of years have made it a less attractive option. As a result, the Imgix Download Transformer was created with two primary use cases in mind:
- Continuing using Imgix for image transforms while reducing cost factors (master images per month and bandwidth).
- Making it easier to move a site off Imgix and start using local, server-based image transforms (i.e., what Imager X calls the
craft
transformer).
What does it do?
The codebase for the Imgix Download Transformer is very small because it mostly leverages existing code from Imager X.
It starts by using the built-in Imgix transformer to create transforms based on the assets and parameters sent in. Imgix transforms are essentially just fancy URLs; no work is done before the transforms are actually requested from Imgix. It will use the standard Imgix configuration from your imager-x.php
config file, so if you already have a working Imgix config, you don't need to do anything.
The next steps are a bit convoluted, but essentially, the transformed files are downloaded using the URLs from the first step and stored locally on your server in the exact same location and with the exact same file name as they would have been if you were using the local craft
Transformer. This exact match is important because it means that if you eventually remove the Imgix Download Transformer and start using local image transforms, Imager X will continue to serve the existing transforms. In other words, the cache will be warm.
Since it taps into the exact code that the Craft Transformer uses, all the functionalities it offers will work. You can configure external storage, post-optimization tools (although, there's no point at this stage), or put a pull CDN in front of your server.
Remind me again, why?
Back to our use cases:
- Cost Reduction: We can continue to use Imgix for transforms, but the metrics that determine pricing are minimized. New master images will only be counted by Imgix for new images that are uploaded and used, or if new transforms for old images are needed. Based on our experience, this will usually be very low for most projects. Bandwidth will also be close to zero since it is limited to downloading the images to your own server.
- Transition to Local Transforms: After letting the Imgix Download Transformer run for a month or two (Google will likely have visited all your relevant pages by then), you'll probably have a fully warmed local cache if you decide to switch to local image transforms.
What's the catch?
There are primarily two caveats to keep in mind:
- Loss of Imgix CDN Benefits: By not letting Imgix serve the images through its CDN,
auto: format
no longer works. You'll have to serve up different formats manually, preferably using<picture>
, just like you would if you used local transforms. Fortunately, this is now super simple with the new Power Pack that was released recently! - Latency: Even though transforms aren't done on the server, there will still be some latency while waiting for Imgix to deliver the image. If a page creates 20 new transforms, Imgix will need some time to generate them, and downloading them will need some. So, just like when using the
craft
Transformer, you'll benefit from configuring automatic generation of transforms for your project.
So that's what you call a hybrid transformer!
Yeah, I guess. Or, just another tool in your image transform tool belt.
You can get it in the plugin store, or read more in the repository. It's free, but since it's a custom transformer you'll need a pro license of Imager X.
Hope you find it useful! 🥷🎉