Short Version: HEIC images need to have even numbered dimensions. In previous versions of ImageMagick installed by Homebrew, libheif 1.7.0 used a kludge to round down image dimensions to even values to allow images with odd numbered dimensions to be converted.
Now libheif 1.8.0 has ditched that kludge and generates images in such cases that macOS seemingly cannot open despite them being valid HEIC files.
While Apple irons out whatever needs to be done to fix this, what can be done in the interim to allow for the clean conversion of such images in a way that allows macOS to open them?
Longer Version: I’ve been using ImageMagick to convert piles of high resolution JPEG images to HEIC format — to save on file space and data transfer times while retaining quality — on and off since around July 2020. I am using macOS Catalina 10.5.6 (19G2021) and ImageMagick has been installed and updated via Homebrew.
This past month something odd happened while converting a small directory filled with images: Seemingly arbitrary images would convert to HEIC, but I could not open them up in the “Preview” app or even Pixelmator in macOS. No preview icon was generated either. Making things weirder is that if I took that HEIC image and then converted it back to a JPEG, the conversion worked. So the HEIC was valid in some way, but not in a way that macOS’s native API could handle.
According to this comment on an issue report on the ImageMagick repo it turns out that libheif — the library that handles HEIC stuff in ImageMagick — was recently upgraded to 1.8.0 and that new version handles the conversion of images with odd numbered dimensions differently than versions of libheif 1.7.0 and earlier. In the case of images with odd dimensions it creates HEIC images that uses a clap
(Clean Aperture) crop transform and macOS apparently has no idea how to deal with that. And checking my pile of unopenable images, they all have at least one dimension (width or height) in an odd number value.
So while this is clearly an issue with macOS and how it natively handles HEIC files, what can I do now to get back to bulk converting images that can be viewed in macOS? Downgrading to libheif 1.7.0 seems messy and is a bit regressive.
If you want to test this for yourself, try this command using this test image on Wikimedia that has a 3111 width by 3333 height; just rename the image test.jpeg
for this:
convert test.jpg test.heic
Or try to do the same using the libheif utility heif-enc
like this:
heif-enc test.jpg -o test.heic
In both cases, the macOS “Preview” app — and other applications — can’t open the generated test.heic
file. But it clearly can be converted back to a JPEG like this from the command line using ImageMagick:
convert test.heic test.jpg