Skip to content

Instantly share code, notes, and snippets.

@Luctins
Created August 28, 2025 14:49
Show Gist options
  • Save Luctins/22336f0e3df75035cb18f3e10642c9fb to your computer and use it in GitHub Desktop.
Save Luctins/22336f0e3df75035cb18f3e10642c9fb to your computer and use it in GitHub Desktop.
A little function to convert png -> jpg with missing extension detection
#!/bin/bash
function png2jpg() {
case $1 in
*.png)
;;
*)
if [ ! diff <(echo -n ".PNG" ) <(dd if=$1 bs=1 count=4) ]; then
echo "input file $1 is not a png"
return 1
fi
echo "input file is a suspected png without extension, continuing"
;;
esac
magick convert "$1" "${1%png}.jpg"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment