mirror of
https://github.com/standardebooks/web.git
synced 2025-07-06 14:50:39 -04:00
iOS16 upholds AVIF standards more strictly than other renderers, which means that the current AVIF images on SE are broken. A fix for generation bug has been added to go-avif (https://github.com/Kagami/go-avif/pull/17) but we can do better. This PR switches out the AVIF generation to cavif (https://github.com/kornelski/cavif-rs) which not only doesn’t suffer from the iOS16 but drops generation time by more than 8 times. For example, here’s a set of three timed runs in both go-avif and cavif on the title card of https://standardebooks.org/ebooks/jonathan-dymond/an-inquiry-into-the-accordancy-of-war-with-the-principles-of-christianity: ``` root@f58fb0beac90:/standardebooks.org/web/scripts# time ./go-avif -e "illustration.jpg" -o "illustration-go-1.avif" --best real 0m31.191s user 1m39.113s sys 0m1.662s root@f58fb0beac90:/standardebooks.org/web/scripts# time ./go-avif -e "illustration.jpg" -o "illustration-go-2.avif" --best real 0m33.097s user 1m49.846s sys 0m0.831s root@f58fb0beac90:/standardebooks.org/web/scripts# time ./go-avif -e "illustration.jpg" -o "illustration-go-3.avif" --best real 0m36.963s user 2m4.235s sys 0m0.711s root@f58fb0beac90:/standardebooks.org/web/scripts# time ./cavif --quality 50 "illustration.jpg" -o "illustration-cavif-1.avif" illustration-cavif-1.avif: 98KB (96840B color, 0B alpha, 242B HEIF) real 0m4.017s user 0m11.600s sys 0m0.051s root@f58fb0beac90:/standardebooks.org/web/scripts# time ./cavif --quality 50 "illustration.jpg" -o "illustration-cavif-2.avif" illustration-cavif-2.avif: 98KB (96840B color, 0B alpha, 242B HEIF) real 0m4.083s user 0m11.857s sys 0m0.091s root@f58fb0beac90:/standardebooks.org/web/scripts# time ./cavif --quality 50 "illustration.jpg" -o "illustration-cavif-3.avif" illustration-cavif-3.avif: 98KB (96840B color, 0B alpha, 242B HEIF) real 0m4.237s user 0m12.339s sys 0m0.093s ``` The executable has been generated via cargo, and has the following qualities: ``` root@f58fb0beac90:/standardebooks.org/web/scripts# file cavif cavif: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=f972071996c58b7a855d04e4c5804f4a3d94f575, for GNU/Linux 3.2.0, with debug_info, not stripped ``` I’m not sure how cavif’s quality 50 matches go-avif’s best flag, but they produce similar file sizes and similar visual quality. There is a slight different in apparent colour space. If this is an issue there are tweaks, but according to the documentation it makes files larger so should be avoided. Given that the titlecards will matches the covers I see no reason to go down that path.
6.5 MiB
Executable file
6.5 MiB
Executable file