Refract - A guided AVIF/JPEG XL/WebP conversion utility for JPEG and PNG sources.

Overview

Refract GTK

Dependency Status

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 start screen. Nice and clean. Viewing a PNG source image. Previewing a WebP candidate to Discard or Keep.

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.

Hence "guided".

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+.

Why?

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!

Features

Format Decoding (Input/Display) Encoding (Output)
JPEG Yes, except CMYK and 16-bit lossless.
PNG Yes*
AVIF Yes Lossless, lossy, RGB, and YCbCr
JPEG XL Yes* Lossless, lossy.
WebP 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.

Refract implements libavif, libjxl, and libwebp directly. This not only ensures full standards compliance and feature/performance parity with each format's official conversion tools — avifenc, cjxl, and 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.

Usage

Refract is pretty straightforward:

  1. Tweak the settings — via the Settings menu — as desired.
  2. Load a single image or an entire directory.
  3. 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:

Action Key(s)
Open File CTRL + o
Open Directory SHIFT + CTRL + o
Toggle Dark Mode CTRL + n
Toggle View SPACE
Discard Candidate d
Keep Candidate k

Installation

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.)

While specifically written for use on x86-64 Linux systems, both Rust and GTK are cross-platform, so you may well be able to build it from source on other 64-bit Unix systems using Cargo:

# Clone the repository.
git clone https://github.com/Blobfolio/refract.git

# Move into the directory.
cd refract

# Build with Cargo. Feel free to add other build flags as desired.
cargo build \
    --bin refract \
    -p refract \
    --release

Cargo will handle the entire build process for you, however many of Refract's dependencies have heavy build.rs scripts requiring additional system libraries. (Who'd have thought image decoders and encoders were complicated?!)

At a minimum, you'll need up-to-date versions of:

  • Clang
  • Cmake
  • GCC
  • Git
  • Make
  • NASM
  • Ninja
  • Rust/Cargo

GTK is a whole other monster, requiring the -dev packages for (at least) ATK, Cairo, GDK, GLIB, GTK, Pango, and Pixbuf. Thankfully, many distributions offer meta packages to make GTK dependency resolution easier. On Debian Buster, for example, installing librust-gtk-dev and librust-gdk-dev should just about cover everything.

This list is (probably) non-exhaustive. If you find you need something else to build on your system, please open a ticket so the list can be updated!

Likewise, if you try building on Mac, please let us know how it goes!

License

See also: CREDITS.md

Copyright © 2021 Blobfolio, LLC <[email protected]>

This work is free. You can redistribute it and/or modify it under the terms of the Do What The Fuck You Want To Public License, Version 2.

DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004

Copyright (C) 2004 Sam Hocevar 
   
    

Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.

DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

0. You just DO WHAT THE FUCK YOU WANT TO.

   
You might also like...
A linear algebra and mathematics library for computer graphics.

cgmath-rs A linear algebra and mathematics library for computer graphics. The library provides: vectors: Vector2, Vector3, Vector4 square matrices: Ma

Signed distance field font and image command line tool based on OpenCL.

SDFTool Signed distance field font and image command line tool based on OpenCL. Build Windows Run cargo build --release in Visual Studio developer x64

A programming language where comments are the first-class citizen and ASCII art flowcharts are the controls!
A programming language where comments are the first-class citizen and ASCII art flowcharts are the controls!

regretti 🍝 A programming language where comments are the first-class citizen and ASCII art flowcharts are the controls! Made for Lang Jam (jam0001) t

@Buildspace project creating a Web3 Solana Dapp with React and Rust
@Buildspace project creating a Web3 Solana Dapp with React and Rust

buildspace Solana GIF Portal Project Welcome 👋 To get started with this course, clone this repo and follow these commands: Run npm install at the roo

Encoding and decoding images in Rust
Encoding and decoding images in Rust

Image Maintainers: @HeroicKatora, @fintelia How to contribute An Image Processing Library This crate provides basic image processing functions and met

Rust library to get image size and format without loading/decoding

imageinfo-rs Rust library to get image size and format without loading/decoding. The imageinfo don't get image format by file ext name, but infer by f

Simple image metadata scrubber. Will remove EXIF, XMP and IPTC metadata.

Simple image metadata scrubber. Will remove EXIF, XMP and IPTC metadata.

Rust Lean Image Viewer - Fast and configurable image viewer inspired by JPEGView by David Kleiner
Rust Lean Image Viewer - Fast and configurable image viewer inspired by JPEGView by David Kleiner

Rust Lean Image Viewer - Fast and configurable image viewer inspired by JPEGView by David Kleiner

mico (minimalistic config file format) encoder and decoder

mico This library implements a parser and emitter for mico (minimalistic config file format). Format example: Name: mico Description: minimalistic con

Comments
  • Package for flathub

    Package for flathub

    Reach across Linux distros could be increased by packaging as a flatpak. If there's appetite for it, there is a guide here for the nitty gritty of how to do it.

    I may try my hand at this, but it won't be quickly as I'm both new to flatpak building and a bit busy.

    enhancement help wanted 
    opened by EpocSquadron 3
Releases(v0.9.1)
Owner
Blobfolio
A small web development firm with big talent & plenty of experience.
Blobfolio
A simple command-line utility (and Rust crate!) for converting from a conventional image file (e.g. a PNG file) into a pixel-art version constructed with emoji

EmojiPix This is a simple command-line utility (and Rust crate!) for converting from a conventional image file (e.g. a PNG file) into a pixel-art vers

Michael Milton 22 Dec 6, 2022
Convert and save photomode screenshots from Red Dead Redemption 2 to JPEG format.

RDR2 Screenshot converter Convert and save photomode screenshots from Red Dead Redemption 2 to JPEG format. QuickStart Just download the executable fi

Timofey Gelazoniya 12 Sep 29, 2022
PNG decoding and encoding library in pure Rust

PNG Decoder/Encoder PNG decoder/encoder in pure Rust. It contains all features required to handle the entirety of the PngSuite by Willem van Schack. p

image-rs 247 Dec 25, 2022
🖼️Combines a Javascript and WASM file into a single executable polygot PNG+HTML file.

WASIMAGE Combines a Javascript and WASM file into a single executable polygot PNG+HTML file. Usage: cargo install wasimage wasimage --wasm-file my.was

Nervive 2 Mar 30, 2022
Oxipng - a multithreaded lossless PNG compression optimizer

Oxipng Overview Oxipng is a multithreaded lossless PNG compression optimizer. It can be used via a command-line interface or as a library in other Rus

Josh Holmer 1.8k Dec 28, 2022
😱 Dead fast thumbnail library for browser and NodeJs! Built with Rust 🦀 and WebAssembly 🕸

thumbo-core ?? Dead fast thumbnail library for browser and NodeJs Built with Rust ?? & WebAssembly ?? ?? About thumbo-core is a thubnail library for b

Victor Aremu 12 Dec 2, 2022
Takes a folder of images (as a palette), and an image, and figures out how to tile the palette to resemble the image!

Takes a folder of images (as a palette), and an image, and figures out how to tile the palette to resemble the image!

Jacob 258 Dec 30, 2022
Encoding and decoding images in Rust

Image Maintainers: @HeroicKatora, @fintelia How to contribute An Image Processing Library This crate provides basic image processing functions and met

image-rs 3.5k Jan 9, 2023
Classical Rainbow Triangle using Rust and Vulkan via vulkano bindings

Vulkano Rainbow Triangle Classical Rainbow Triangle using Rust and Vulkan via vulkano bindings. Based on the vulkano triangle example Quick Start $ ca

Tsoding 14 Dec 30, 2022
Lust is a static image server designed to automatically convert uploaded image to several formats and preset sizes

What is Lust? Lust is a static image server designed to automatically convert uploaded image to several formats and preset sizes with scaling in mind.

Harrison Burt 242 Dec 22, 2022