Refract is a guided image conversion tool written in Rust for x86-64 Linux systems with GTK.
It takes JPEG and PNG image sources and produces AVIF, JPEG XL, and WebP clones.
The program is named after — and works like — eye doctor Refraction Tests. It generates candidate images at various qualities, asking at each step how it looks, and uses that feedback (you provide) to arrive at the smallest possible "acceptable" output.
The beauty of this approach is that it moots the need for exhaustive testing. Refract's quality stepping works by selecting the mid-point between moving min/max boundaries. Each answer you provide adjusts the range, allowing the final, perfect result to be discovered in just 5-10 steps instead of 100+.
Every image is different. The idea of a "Magic Bullet" format is a myth.
If you want to truly maximize the quality and size of next-gen copies, you cannot rely on hardcoded constants or fancy SSIM analysis. That will result in frequent over- or under-compression, and some images will just come out looking… worse.
You have to actually use your eyes. And you have to pay attention to the resulting file sizes. Sometimes newer formats will result in larger output than the original source, defeating the purpose!
While you can do all of this manually — running multiple programs hundreds of times for each and every source you want to convert — that would be incredibly tedious and easy to screw up.
Refract helps makes that manual process less tedious and more foolproof.
It automatically uses the strongest (slowest) possible compression settings for each format, keeps track of file sizes and qualities along the way, can process inputs en masse, and reduces the number of conversion tests by around 90%.
Should you use it for every image ever?
No, probably not.
The next generation formats, particularly AVIF and JPEG XL, require a lot of computation to eek out their extra byte savings. All those minutes will add up quickly.
But if you're looking to obsessively optimize a small project or single web page, Refract is the way to go!
|Format||Decoding (Input/Display)||Encoding (Output)|
|JPEG||Yes, except CMYK.|
|AVIF||Yes||Lossless, lossy, |
|JPEG XL||Yes*||Lossless, lossy.|
*Refract does not support animated images. Without going too far down that rabbit hole, let's just say that if GIF can't handle the job, it should be a video, not an image.
In other words, Refract takes JPEG and PNG sources — either individual files or entire directory trees — and turns them into AVIF, JPEG XL, and/or WebP outputs.
libwebp directly. This not only ensures full standards compliance and feature/performance parity with each format's official conversion tools —
cwebp respectively — it also means you don't need any of that crap separately installed to use it!
All conversion takes place at Pixel Level and is intended for displays with an sRGB color space (e.g. web browsers). Gamma correction, color profiles, and other metadata are ignored and stripped out when saving next-gen copies.
Refract is pretty straightforward:
- Tweak the settings — via the
Settingsmenu — as desired.
- Load a single image or an entire directory.
- Sit back and wait for any feedback or save prompts.
For best results, be sure to optimize your input sources before re-encoding them with Refract. (Our Flaca CLI tool can help with this!)
For keyboard afficionados, the following hot-keys may be used:
|Open File|| |
|Open Directory|| |
|Toggle View|| |
|Discard Candidate|| |
|Keep Candidate|| |
Debian and Ubuntu users can just grab the pre-built
.deb package from the release page.
(Arch Linux users can probably use the
.deb too, but may need to adjust the icon and
.desktop paths to match where your system likes to keep those things.)
To build it from source, refer to the documentation in the repo.