HUGO

HEIC Image Conversion

I would like to convert images from the HEIC (aka HEIF) format to something that can be processed by the Hugo image processors. I’ve tried using the .heic files as an image but the resizing functions fail due to the file format not being supported.

The go4/media package has support for converting from HEIF to JPG. What would be the logical way for me to incorporate that functionality into my Hugo workflow? I’ve read a few posts that seem to indicate there is no modular way of adding custom functions to the Hugo templates.

Is forking the repository the best approach to add this feature? Is there existing code that would provide good patterns to improve the chances of this getting included if made into a PR?

Thanks

Maybe it would be simpler to convert the HEIC images to png/jpeg/webp and work with those? If you’re on a Mac, you could probably use a Folder action or some other automation tool to perform the conversion.

1 Like

I currently use ImageMagick’s mogrify command to translate the HEIF files to JPG but that wasn’t the question. I’m looking to add support for HEIF files to Hugo so they can be handled like all the other image formats.

In the absence of high demand or urgency for this functionality, it is unlikely that a PR would be accepted unless it provided or leveraged a native Go decoder.

Given that this is the format that iPhones are generating natively, I suspect the demand will likely grow.

When you say “native Go decoder”, does the go4/media package mentioned in my original post not fit that definition?

No, it does not.

https://pkg.go.dev/go4.org/media/heif

This package does not decode images; it only reads the metadata.

https://github.com/jdeng/goheif

based on libde265

During my brief search I was unable to find a native decoder.

Thank you! I understand now and will start hunting down a native decoder before implementing something.