Skip to content

Instantly share code, notes, and snippets.

@TonyWhite
Created January 12, 2022 11:49
Show Gist options
  • Select an option

  • Save TonyWhite/3878891fc2bea4ce009a9fe4e6d3874c to your computer and use it in GitHub Desktop.

Select an option

Save TonyWhite/3878891fc2bea4ce009a9fe4e6d3874c to your computer and use it in GitHub Desktop.
Bulk convert HEIC images to Jpeg
#!/bin/bash
# OBJECTIVE
# Bulk convert HEIC images to Jpeg
# DEPENDENCIES
# imagemagick
# USAGE
# 1) Put script in same folder of HEIC files
# 2) Run the script
# Lists HEIC files (case insensitive)
FILES=(`ls -1 | grep -i ".HEIC"`)
echo "Found ${#FILES[@]} HEIC files"
# Make output dir
mkdir -p "HEIC_to_JPG"
# Process all files
for ((INDEX=0 ; INDEX < ${#FILES[@]}; INDEX++)); do
# Print human readable index
HUMAN_INDEX=$((${INDEX} + 1))
printf "Convert $HUMAN_INDEX of ${#FILES[@]}..."
# Convert the file to output dir
convert "${FILES[$INDEX]}" "HEIC_to_JPG/$(echo ${FILES[$INDEX]} | cut -f1 -d '.').jpg"
# Print "OK" if OK
if [[ "$?" == "0" ]]; then
echo "OK"
else
echo "ERROR on ${FILES[$INDEX]}"
fi
done
# Print... THE LAST MESSAGE!
echo "Job finished"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment