Skip to main content

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

A lot of files scattered around the internet have pointlessly large file sizes, which modern software can optimize out, or they weren't meant to be there in the first place.

The above commands try to do so without losing any data. Further file size savings can be achieved by means of exiftool and removing extra unnecessary EXIF information, but that is entering lossy territory, as it can often carry useful or necessary information.