Optimization
# JPEG/JFIF - lossless
jpegoptim "${filepath}"
# PNG (and ICO that is PNG) - lossless
oxipng -o max "${filepath}"
# SVG - might lose data that other scripts may rely on if the SVG is somehow parsed
# see `plasma/breeze:.../build.sh` where name metadata is fed to inkscape
# Verification that result is smaller is necessary as svgo may actually be
# adding data necessary for correct rendering everywhere.
# That may or may not be desirable, bad for filesize, good for compatibility.
svgo --multipass --input "${filepath}" --output "${tempDir}/svgo-$$.temp"
# BMP -> PNG - lossless, but probably requires editing other things that link to BMP
convert "${filepath}" "${filepathWithoutExtension}.png"
# PDF - lossless recompression
pdftk "${filepath}" output "${filepath}.tmp" uncompress
pdftk "${filepath}.tmp" output "${filepath}.packie" compress