HEIC to jpeg in Bash

Posted by Andrew Denner on April 27, 2022 · 2 mins read

So you just transferred a batch of photos from your new Apple iPhone or Android Galaxy S21+ and realize that they are all saved as an odd new format .heic.

What is this High Efficiency Image File Format and how can you get back to the .jpg that you know and love? The technical standard was finalized in 2015 and Apple has been using them since 2017 in iOS 11. It is a technically better standard, allowing the storage of non-destructive editing transforms and sequences of photos (like burst shots) in the same package. However, as with all new things, the adoption has been slow.

Here you are now with a folder full of images, and being a Linux user, you want to use your shell to edit them. Don’t worry, I’ve got your back (because I just had to figure it out).

In Debian based distros (ubuntu) you will want to run the commands:

sudo apt update; 
sudo apt install libheif-examples

(update your packages list and then install libheif-examples)

After this completes, since I am impatient, we are going to use xargs and sed to speed things along. (the option -P8 will run 8 separate processes at the same time)

In this case, I want to save my newly minted jpegs to a new folder named jpg (created with the command mkdir jpg)

 ls *.heic | xargs -I ! -P8 bash -c 'heif-convert ! jpg/`echo !|sed "s/.heic/.jpg/"`' -%

(note if your files end in .HEIC you will need to update the ls part of it)

That and some time is all it will take. Note that this also will work just fine for WSL2 in windows. (It is Linux after all).

Here is an example on Ubuntu 22.04 Jammy Jellyfish