-
-
Save suapapa/ed4ed713cec0ac9adbcb025abb46d496 to your computer and use it in GitHub Desktop.
Recursively converts .heic files to .jpg for a specified root directory
This file contains 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 | |
# Recursively converts all HEIC files to JPG for the specified directory. | |
# Skips any files that have already been converted. | |
# Requires ImageMagick | |
# | |
# usage: ./heic2jpg.sh [RootDirectory] | |
# | |
rootDir=$1 | |
set -e | |
if [ -z "$rootDir" ] | |
then | |
echo "Need to specify root directory." | |
exit 1 | |
fi | |
find $rootDir -type f -iname "*.heic" | while read f | |
do | |
ft=$(file -b "$f") | |
n=$(echo $f | sed 's/.heic/.jpg/I') | |
if [[ $ft == JPEG* ]]; then | |
echo "wrong file ext. mv '$f' to '$n'" | |
mv "$f" "$n" | |
continue | |
fi | |
if [ -f '$n' ]; then | |
echo "alredy converted. Skipping $f" | |
continue | |
fi | |
echo "converting '$f' to '$n'" | |
magick "$f" "$n" | |
rm $f | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment