#!/bin/sh set -eu target=${1:?target} size=${2:-normal} case $size in normal) px=128 ;; large) px=256 ;; x-large) px=512 ;; xx-large) px=1024 ;; *) exit 1 ;; esac md5=$(echo "file://$(readlink -e "$target")" | md5sum | cut -d' ' -f1) dir=${XDG_CACHE_HOME:-$HOME/.cache}/thumbnails/$size path=$dir/$md5.png printf '%s' $path [ -n "${MKTOES_NOGEN:-}" ] && exit 0 test -f $path && exit 0 mkdir -p $dir chmod 700 $dir tmp=$dir/.$$.$md5.png ffmpeg -hide_banner -i "$target" -vf scale=$px:$px:force_original_aspect_ratio=decrease $tmp 2>/dev/null mv -f $tmp $path chmod 600 $path