Convert Apple HEIC to JPG on Linux with this simple Bash script.

This Bash script will convert Apple HEIC to JPG. It will also save you a little space without losing image quality in the process. It will delete HEIC files that were successfully converted so if you don’t want that, comment the rm line.

If you just want to copy photos and movies from iPhone and don’t need to manage your photo collection give Rapid Photo Downloader a look. It took very little time to move all my son’s photos and movies to an external drive directly from the iPhone using Rapid Photo Downloader. That was around 5000 totals files. I myself use Shotwell and have no issues downloading my images. DigiKam works well too.

Apple HEIC to JPG config.

This script uses Image ImageMagick so make sure it’s installed for your platform. You need version 7. I wrote this on Arch so you would do:

sudo pacman -S imagemagick

magick -version

On Pop! OS (Debian, Mint, Ubuntu, etc.) the version in the repo is 6. If you have it installed you need to uninstall and manually compile by following the commands below:

sudo apt update

sudo apt purge imagemagick

sudo apt install build-essential 

cd ~

cd Downloads

wget https://imagemagick.org/archive/ImageMagick.tar.gz

tar xvzf ImageMagick.tar.gz

cd ImageMagick     (Hit tab or copy the name from the unzipped folder.)

./configure 

make

sudo make install 

sudo ldconfig /usr/local/lib

magick -version    (Verify you now have version 7)

Setup the script

Simply copy the code, change the path to where you will place your images. If you want to keep the HEIC files comment or remove the rm line. Save the script as heic2jpg.sh , or whatever you like. Then right click the file and set to executable. If you want bigger file sizes you can up the quality but I honestly saw no benefit at anything greater than 80%.

Once saved and set to executable open the terminal, cd to the folder where you saved the script, and type:

./hiec2jpg.sh

That’s it…

Here’s the code:

#!/usr/bin/env bash

# Move to folder containing heic files.
cd "/path/to/heic images"

# Find all heic files.
find . -type f -iname "*.heic" | while read f
do
    # Convert heic to jpg.
    magick "$f" -quality 80 "$f.jpg" # Version 7.x required.

    # Delete the original heic file.
    if [ $? -eq 0 ]; then
        rm "$f"
    fi
done

If you would like HEIC thumbnails in Gnome Files and image viewer see this.