FLR Optimizer is a AWK-based script for optimizing JSON formatted FLR files (exported from Rive). This experimental script was greatly influenced by the SVGO project. Please don't take it too seriously.
FLR files, especially those exported in JSON format, usually contain a lot of useless information. Such as non-optimal, too long values and so on, that can be safely converted without affecting the FLR rendering result much.
AWK is a domain-specific language designed for text processing and typically used as a data extraction and reporting tool. It is a standard feature of most Unix-like operating systems, such as macOS and Linux distributions.
Note about Windows: AWK is not available in Windows by default. Please use either gawk (you will need to change the command syntax a little) or in Windows 10 (from build 14328 and later), simply run a command from Linux Bash Shell (i have personally tested it there too).
In terminal navigate to folder with your FLR file and run following command:
awk '{
while (match($0, /[0-9]+\.[0-9]+/)) {
printf "%s%.2f", substr($0, 1, RSTART-1), substr($0, RSTART, RLENGTH)
$0 = substr($0, RSTART+RLENGTH)
}
print
}' original.flr > optimized.flr
- 2f is the number of digits after the decimal point (I do not recommend reducing it below 2).
- original.flr is the name of your FLR file.
- optimized.flr is the name of optimized FLR file.
The FLR file from the assets folder, in this repository, was optimized by this script. To test results of this script — please run following commands in terminal:
flutter upgrade
git clone https://github.com/tsinis/flro.git
cd flro
flutter create .
flutter run
This project is released under the terms of the MIT license.