De-HEIC-ifying images

What's this for? (TL;DR)

If you have an iPhone and it gives you HEIC instead of JPGs, this is a way to convert the files to something that non-Apple systems can digest easily.

Scripts first

All the oneliners I mention below use ImageMagick. You can install it with Homebrew on macOS:

brew install imagemagick

And once ImageMagick is installed in your system...

To convert from HEIC to JPG:

mogrify -format jpg *.HEIC

Convert and resize to 50% of the original size:

mogrify -resize 50% -format jpg *.HEIC

And to also remove EXIF metadata (this includes location data):

mogrify -resize 50% -strip -format jpg *.HEIC

I normally put all the pictures I want to process in a folder and duplicate it first just in case something gets accidentally destroyed (specially if I'm playing with parameters).

Then I cd to that folder from the command line and run the appropriate script. E.g. sometimes I want to just resize and strip and I don't need to convert to JPG because the phone arbitrarily gave me JPG.

So something like this would work:

mogrify -resize 50% -strip *.JPG

If your phone is an absolute bastard like mine and gave you both HEIC and JPG in the same "drop", process your JPG files first and then the HEIC ones. Otherwise if you do it the other way you'll resize HEIC files twice.

Background

My older and conveniently sized iPhone SE died a while ago and I got a bigger and flashier iPhone which had more and better cameras (it went from 1 to 3 back cameras!)

Consequently more megapixels also means more space is needed to capture all that data. iOS kindly tries to help by storing images in the HEIC, rather than the JPG format. HEIC supposedly has much better compression rate which means that I get to save space on my phone and take more pictures.

This is nice, except that seemingly only things that are deep into the Apple ecosystem are nicely compatible with HEIC out of the box. For example, mac OS and Preview.app.

So if for example you want to upload your pictures to social networks? Can't do that. They either won't recognise the format or the results will be unpredictable. Browsers do not understand the format (and with this I mean, the browser which I want to use, not Safari). What if I want to upload images to my food blog which is running WordPress? It doesn't work either.

I have searched for WordPress plugins or something in PHP that could parse HEIC, but found nothing that looked like it would work, or that wasn't a scam, or abandonware, or just a declaration of intentions.

I have also tried to devise some sort of phone-side automation using the "Shortcuts" app that would enable me to "Save as JPG" the images if I use the "Share..." functionality... and it didn't work either.

Additionally, and this is perhaps the most nerve-wracking thing, it is not consistent. Sometimes you select a bunch of images to send to the computer from the phone, and it exports some as JPG and some as HEIC.

So I temporarily settled for sending the images to my laptop and processing them before uploading as JPG. It does feel like a return to Ye Olde Times when our pictures came from cameras which weren't connected to the internet at all, and it is slightly inconvenient when on the move, but it has several upsides:

  • It's relatively easy to automate
  • I find it easier to edit the images on the computer (it's also nice to see the details in a bigger screen...!)
  • I can make sure images are stripped of location, etc (if I'm posting pictures about something I cooked at home, I don't want to broadcast the location to the world)
  • It's faster to run scripts locally than on a remote server as my laptop has a faster CPU and more memory

A clarification: it's not that I cannot export from the phone as JPG if I really want to. It's that...

  • it is not obvious how to do it with the default iOS services
  • you can install apps that let you export one image at a time (which is what I'd use in an emergency "on the move")

To be somewhat fair, you can configure iOS to save as JPG but it applies to all subsequent images you take from then on, and thus you use more space. I don't want this! I want to have my cake (efficient space usage on my device) and eat it too (being able to share multiple images as JPG without installing plugins).

I suppose I'm in that small category of users who do not upload everything to the cloud by default, and so Apple has no interest whatsoever in implementing the use case of "sharing images in a compatible format".

Sigh! I hope the scripts are useful for you.

And if not, Terence Eden also wrote some words about coping with HEIC. Maybe his tricks will help you!