As some of you might know, iPhone has its own picture file format. The HEIC(High-Efficiency Image Container) format. it doesn’t always work when you want to upload it to many websites. There are some websites out there that can convert it for you. It might be okay for some photos that you don’t care about. But for some family photos, you might not want to share them on some random websites.
I found that on Linux, you can simply install a command-line tool called heif-convert. To use it, simply install the libheif-examples command-line. heif-convert just comes with it for free. To install, run the following command:
sudo apt-get install libheif-examples
You can easily convert your HEIC file with the following command:
heif-convert [original-file-name] [file-name-with-jpg-or-png-extension]
For example, if you have a file called IMG_1234.HEIC and want to convert it to IMG_1234.jpg, you can simply run:
heif-convert IMG_1234.HEIC IMG_1234.jpg
Easy, isn’t it? This command can only convert 1 file at a time, which can be annoying when you need to convert multiple files. If you’re lucky, all of the files you drag from the iPhone will have lowercase extension “heic”. You can run this script to convert them:
for file in *.heic; do heif-convert $file ${file/%.heic/.jpg}; done
Sometimes, some files are in lowercase and some come with uppercase. There are many ways to deal with this issue. You can rename all the files to lowercase and then run the above command, you can write a program that reads all the files and then run the heif-convert command.
I took the route to learn about how to do that with a bash script. My script will read all the files that contain “.heic” or “.HEIC” in the filename. Then convert them into jpg format with the heif-convert command.
I created a GitHub repository for any handy command in the future. You can download the heic-converter.sh executable from here. To run it:
./heic-converter.sh
If my note helped, please consider buying me a coffee😁.
Cheers,
Lok
Reference: