Created
August 19, 2023 08:15
-
-
Save uriel1998/71a94220feb2b9f159ff4126839163c0 to your computer and use it in GitHub Desktop.
convert images between formats -- uses imagemagick and heif-convert
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 | |
# uses heif-convert: https://pypi.org/project/heif-convert/ | |
# uses imagemagick: https://imagemagick.org/ | |
if [ "${2}" == "" ];then | |
echo "We need an output format, thanks." | |
exit 99 | |
fi | |
# Just a single file | |
if [ -f "${1}" ]; then | |
echo "Converting $1 to $2 format" | |
filename=$(basename -- "$1") | |
extension="${filename##*.}" | |
ext_lower=$(echo "${extension,,}") | |
g="${1%.*}" | |
if [[ "$ext_lower" = "heic" ]];then | |
heif-convert -f "$2" "$filename" "$g.$2" | |
else | |
convert "$filename" "$g.$2" | |
fi | |
fi | |
# for an entire filetype. Usage: | |
# convert_images heic png | |
# convert_images pdf jpg | |
# etc | |
for f in *.$1; do | |
echo "Converting $f to $2 format" | |
filename=$(basename -- "$f") | |
extension="${filename##*.}" | |
ext_lower=$(echo "${extension,,}") | |
g="${f%.*}" | |
if [[ "$ext_lower" = "heic" ]];then | |
heif-convert -f "$2" "$filename" "$g.$2" | |
else | |
convert "$filename" "$g.$2" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment