Convert HEIF Images to JPG or PNG on Linux (With Commands)

HEIF photos (those with the .HEIC file extension) can store image data more efficiently than JPG or PNG, which yields a smaller file size. But the glaring drawback is that HEIF doesn’t enjoy widespread support. If you have some HEIF photos that you need to convert to a different format, this can be done from the Linux command line.

In this tutorial, you’ll see how to convert HEIF images to JPG or PNG with Linux commands.

Install libheif on Linux

The heif-convert command is used to convert HEIF images to other formats. Use the appropriate command below to install the libheif package, containing the heif-convert utility, with your system’s package manager.

Ubuntu, Debian, and Linux Mint:

$ sudo apt install libheif-examples

Fedora:

$ sudo dnf install -y https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm
$ sudo dnf install libheif

Arch Linux and Manjaro:

$ sudo pacman -S libheif

Convert HEIF images to JPG or PNG

In the commands below, we are converting image files with the .HEIC file extension (notice the capitalization). Apple’s iPhone – the primary source of HEIF photos, probably – always capitalizes file extensions, but you can change these examples to lowercase if necessary.

Command 1. Use the following syntax with the heif-convert command to convert a photo. Simply supply the name of the input file (the HEIC photo) followed by the name of the output file (the new JPG or PNG photo):

$ heif-convert image.HEIC new-image.jpg

or…

$ heif-convert image.HEIC new-image.png

Command 2. The -q option will control the quality level of the output image. To keep your converted photos looking sharp, you should use the -q 100 setting to convert at maximum quality:

$ heif-convert -q 100 image.HEIC new-image.jpg

Command 3. If you have a lot of HEIF photos to convert, you can use a Bash for loop to bulk convert hundreds or thousands of HEIC photos at once:

$ for f in *.HEIC; do heif-convert -q 100 "$f" "$f.jpg"; done

Command 4. A reader also suggested the following Bash loop which will bulk convert HEIC files while removing the original file extension:

$ bash -c 'for f in *.HEIC; do g=${f%.*}; heif-convert -q 100 "$f" "$g.jpg"; done'

Command 5. If you have HEIF files scattered throughout subdirectories, you can use the find command to traverse subdirectories and convert every .HEIC (or .heic) file that it finds:

$ find . -iname "*.heic" -exec heif-convert -q 100 {} {}.jpg \;

10 thoughts on “Convert HEIF Images to JPG or PNG on Linux (With Commands)”

  1. Thank you! My iPhone saves to HEIC to save space, and the website I work with won’t accept the files. This made it quick and easy!

  2. Super useful and just did it. Special mention to arch-linux support given. Just used it and awesome conversion for printing it out.
    Keep going.

    thanks

  3. Thanks for the article!
    I slightly tweaked one of your commands so the target filename doesn’t have the `.heic` part (thus making it easier to remove the original files afterward):

    bash -c 'for f in *.heic; do g=${f%.*}; heif-convert -q 100 $f $g.png; done'

    HTH ^_^

    1. Thanks for the suggestion. We’ve added your example to the article while tweaking it slightly so that it can handle input file names that contain spaces.

  4. This is amazing, I can not believe I have been doing these conversions manually for so long. This is literally saving me hours of work. I am doing 1700+ photos and have been dreading doing this for a year now. The wife will be so happy to be able to view the photos on a Windows computer prior to submitting them to a print house. While I love how Apple does the photo compression, it is a pain in the butt for the users that use other OS platforms. So glad I came across this site… being new to the Linux platform…I am thankful that someone can do this better and faster. Thank you!!

  5. Thanks for the article!

    I use the command below, because I found that heif-convert did not keep track of pictures that were rotated using the EXIF tags. Image Magick, “magick”, makes use of the same libheif library, but also watches and adjusts the EXIF rotations for you. If you don’t include the -quality parameter, it seems to default to 92.
    “`
    for f in *.HEIC; do g=${f%.*}; magick “$f” -quality 92 “$g.jpg”; done
    “`

Leave a Comment

Your email address will not be published. Required fields are marked *