Skip to content

Instantly share code, notes, and snippets.

@bradmartin333
Last active October 31, 2023 14:58
Show Gist options
  • Save bradmartin333/0ff9e60f5521e31b16e20591e14a4ae1 to your computer and use it in GitHub Desktop.
Save bradmartin333/0ff9e60f5521e31b16e20591e14a4ae1 to your computer and use it in GitHub Desktop.
batch convert HEIC images to PNG with WSL2 and ImageMagick
#!/bin/bash
: ' Setup
Put script in dir with HEIC images
Install imagemagick: sudo apt install imagemagick
Allow larger cache
- sudo nano /etc/ImageMagick-6/policy.xml
- change <policy domain="resource" name="disk" value="1GiB"/>
to <policy domain="resource" name="disk" value="8GiB"/>
'
output_dir="heic_to_png"
if [ ! -d "$output_dir" ]
then
mkdir $output_dir
echo "Created output directory"
else
echo "Output directory already exists."
echo "Please remove or rename it."
exit 1
fi
files=($(pwd)/"*.HEIC")
regex="\/([^\/]+).HEIC"
for file in $files
do
if [[ $file =~ $regex ]]
then
name="${BASH_REMATCH[1]}.png"
echo $name
convert "$file" -quality 50 "$output_dir/$name"
else
echo "unable to parse $file"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment