Search | Running | Sailfish OS | All Posts | About Me

Script to convert HEIC image files to PNG

June 02, 2025 — Nico Cartron

My iPhone device produces HEIC image files - which are not widely recognised when used on my blog, so I'd rather use PNG files.

Here's a quick script that does this, the only prerequisite is to have ImageMagick installed on your system.

#!/bin/sh
# Script to convert HEIC files (from iPhone) to PNG                             
# Nico 2025-05-19

if [ $# -lt 1 ]                                                                 
then                                                                            
  echo "Usage: $0 <folder>"                                                     
  exit                                                                          
fi                                                                              

if [ ! -d $1 ]                                                                  
then                                                                            
        echo "folder DOES not exist"                                            
        exit                                                                    
fi                                                                              

for i in `ls "$1" |grep '.HEIC$' |cut -d. -f1`                                  
do                                                                              
        magick "$1/$i.HEIC" -quality 95% "$1/$i.png"                            
        if [ $? -eq 0 ] # we delete the original HEIC file only if the conversion was successful
        then                                                                    
                rm $1/$i.HEIC                                                   
        fi                                                                      
done

Tags: IT


I don't have any commenting system, but email me (nicolas at ncartron dot org) your comments!
If you like my work, you can buy me a coffee!