Contents

Converting iPhone HEICs to JPEGs in Bulk — the Bash Way

Because I just wanted a normal picture and Apple hates standards.

If you’ve ever tried pulling your iPhone photo library onto your PC, you might’ve noticed two things:

  1. Apple stores images in .HEIC format, which is something you’ve never heard of and don’t want to deal with
  2. They nest photos inside a directory structure that looks like it was designed by a random number generator

All you wanted was a bunch of normal JPEGs. But instead, you’re stuck with mystery folders full of files your software can’t open. Neat.

The Problem

  • iPhone stores images in .HEIC, which Windows kind of supports… but kind of doesn’t
  • You have hundreds of photos, spread across a maze of folders
  • You just want .jpg files you can email, upload, or open without consulting the App Store

The Solution

This short Bash script recursively converts all .HEIC files to .jpg, flattening the result into a single target directory. It can also handle duplicates and ignore irrelevant files:

#!/bin/bash

# Source directory where your nested photos are
SOURCE_DIR="put/source/directory/here"

# Target directory to save converted JPEGs
TARGET_DIR="/put/target/here"

mkdir -p "$TARGET_DIR"

find "$SOURCE_DIR" -type f \( -iname '*.heic' -o -iname '*.HEIC' \) | while read -r filepath; do
    filename="$(basename "$filepath" .HEIC)"
    filename="$(basename "$filename" .heic)"  # covers both upper/lower case

    # Ensure unique names in case of filename collisions
    output_file="$TARGET_DIR/${filename}.jpg"
    count=1
    while [[ -e "$output_file" ]]; do
        output_file="$TARGET_DIR/${filename}_$count.jpg"
        ((count++))
    done

    # Convert using ImageMagick
    convert "$filepath" "$output_file"
    echo "Converted: $output_file"
done

Dependencies

This script works on linux and Windows with WSL.

It requires ImageMagick, which you can install on Ubuntu with:

sudo apt update && sudo apt install -y imagemagick libheif1

Some versions of ImageMagick don’t include HEIC support out of the box. If you get errors, try installing libheif-dev and rebuilding, or use a tool like heif-convert from the libheif-examples package.

Yes, this script will overwrite nothing and keep filenames unique. You’re welcome.

Final Thoughts

This isn’t groundbreaking automation. But it’s the kind of thing that saves you an afternoon of suffering—which is honestly what scripting is all about. Write something once, and let it quietly do your dirty work forever.

Now go convert those cursed files and reclaim your photo library.