Created
July 6, 2021 22:47
-
-
Save rietta/14d1a04ad1af099624decdf5b462ef70 to your computer and use it in GitHub Desktop.
Shell script to batch convert HEIC files to jpeg, leaving the original and its converted side by side. Requires Mac OS or Linux, the find command line tool, and ImageMagick
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'shellwords' | |
files = `find . -iname '*.heic'`.split("\n") | |
files.each do |original_file| | |
output_file = original_file.gsub(/\.heic\z/i, ' Converted.jpg') | |
if File.exist?(output_file) | |
STDERR.puts "Skipping output #{output_file} exists." | |
else | |
cmd = "convert #{Shellwords.escape(original_file)} #{Shellwords.escape(output_file)}" | |
puts cmd | |
system cmd | |
end | |
en |
or without needing Ruby on Linux ( and perhaps OS X with brew ):
sudo apt-get install libheif-examples # ( install the library )
for i in *.heic; do heif-convert "$i" "${i%.*}.jpg"; done
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you very much @RandelP .
I missed the requirement at gist description, I was expecting the comment at batch-convert-heic.rb body :)