Created
August 28, 2025 14:49
-
-
Save Luctins/22336f0e3df75035cb18f3e10642c9fb to your computer and use it in GitHub Desktop.
A little function to convert png -> jpg with missing extension detection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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