A macOS script to convert many HEIC images to JPG or PNG format

If you ever need a macOS Unix shell script to convert many HEIC images to JPG or PNG format, I just wrote and used the following shell script, which uses the ImageMagick library, and I can confirm that it works.

As a word of warning before using this code, make sure you back up your images before running the script, because it will operate on ALL HEIC images in the directory it is run:

# WARNING: make a backup copy of all your images before
#          running this code.

extension=HEIC
for inFile in `ls *.${extension}`
do
    baseFilename=`basename $inFile .${extension}`
    outFile="${baseFilename}.jpg"
    echo "$inFile --> $outFile"
    magick $inFile $outFile
    mogrify -resize 50% $outFile   # make the image 50% of the original size
done

There may be better ways to do this, but the magick and mogrify commands are part of the ImageMagick library, and they do the work of transforming the HEIC images to JPG images in this example, and can also be used to transform the images to PNG and other formats.

I just saved that shell script code (Bourne shell syntax) to a file, made it executable, and ran it, and it properly converted the HEIC images to JPEG images.