Skip to content

Instantly share code, notes, and snippets.

@filipeandre
Forked from rietta/batch-convert-heic.rb
Created April 13, 2024 10:45
Show Gist options
  • Save filipeandre/50d5a11dde8230d275126d29a6db684a to your computer and use it in GitHub Desktop.
Save filipeandre/50d5a11dde8230d275126d29a6db684a 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
#!/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
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment