Converting HEIC files to JPG or PNG on Ubuntu 18.04

HEIF stands for High Efficiency Image Format (file extension HEIC i.e. filename.HEIC). It is a new (ish) image file type.The HEIF image format builds images with a smaller file size and better image quality than the older jpeg standard. That’s why Apple has moved over to it as its default image standard on their new phones. Evidently Android will soon too. So how do you go about converting HEIC files into JPG? On Ubuntu 18.04 there’s a handy little package called heif-examples you just have to install it. As so:

sudo apt-get update
sudo apt-get install libheif-examples

Now to convert a file to (say) jpg on the command line its:

heif-convert filename.HEIC filename.jpg

That appears to convert the file to a jpg with 100% quality. With me I ended up with a jpg that was about 30-35% larger than the HEIC file. You can though reduce the size of the jpg by reducing the quality of the conversion. Like so:

 

heif-convert -q 75 filename.HEIC filename.jpg

The -q value can go from 100 (default) to whatever you can get away with. For me (and family snaps) 75 always seems a good compromise. Again with a short simple test my 75% quality jpg output file was smaller than the original HEIC file by about 20%.

Factfulness by Hans Rosling
Things ARE better than you think. Don’t believe the doomsters. Here is why they are wrong!
8500 5* reviews

I also tried the conversion to png files but I found that the resulting png file inflated the file size by 700%. I hasten to add though the image being used was not really suitable for png. But even so the image came out 5% bigger than just by using Gimp to convert the 100% jpg to png at level 9 compression. I also found I couldn’t change the compression on the png. Adding -q 75 or -q 9 (or whatever) did not affect the final png file size. This is probably my fault. If you know how to do this please enlighten me.

You can also go the other way and convert jpgs to HEIC files. But this needs a different tool from the same repository and in it’s simplest form you use it like this:

heif-enc filename.jpg

This will generate a HEIC file of the same name in the same directory

There are more options with this command than with heif-convert the full list is here. The main ones (imho) are:

  • -q Defines the quality of the output heif image. Like hief-convert this goes from 0 – 100
  • -L This makes the output HEIC file lossless and overrides -q (if it exists)
  • –no-alpha This (I think) removes the background making the image transparent.
  • -o Defines the output file name.

Interestingly, when I tested this command I found I got better compression when I specified the output filename.
i.e.:

heif-enc filename.jpg -o otherfilename.HEIC

Than when I just let it default. I don’t know why.

So there’s how to go about converting HEIC files into JPG files (and PNG’s too – with reservations)

Anyway here’s some serious respect to the guy(s) who wrote this converter.
You can find more about them here. The repository for this code with further information (especially on heif-enc) is on this Github Link.

My other Linux/Ubuntu Howto’s and Gotcha’s are on this link.

One thought on “Converting HEIC files to JPG or PNG on Ubuntu 18.04

  • Benjamin Balder Bach says:

    Thanks so much for the tip!

    I have this command hand for converting everything in the current folder:

    find -name ‘*.heic’ -exec heif-convert {} {}.jpeg \;

Leave a Reply

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

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>